Skip to content

Instantly share code, notes, and snippets.

@ricard-inho
Last active January 28, 2019 15:30
Show Gist options
  • Save ricard-inho/5ff0e59f79a6eac8189994f9db201019 to your computer and use it in GitHub Desktop.
Save ricard-inho/5ff0e59f79a6eac8189994f9db201019 to your computer and use it in GitHub Desktop.
Useful Git Commands

GitHub with command line

Cd into the repository and check what files are modified $ cd myproject $ git status

Commit the files that you staged in the local repository (example: README.md) $ git add README.md

To unstage the file use $ git reset HEAD README.md

Commit the files that you have staged git commit -m 'Message'

Push the changes $ git push

Add the files in you

Many remote branches & fetch them all at once

$ git pull --all

Clone a remote git repository

Check the original link here

Clone a remote git repository and cd into it:

$ git clone git:://example.com/myproject
$ cd myproject

Next, look at the local branches in your repository:

$ git branch
* master 

But there are other branches hiding in your repository! You can see these using the -a flag:

$ git branch -a
* master
  origin/HEAD
  origin/master
  origin/v1.0-stable
  origin/experimental 

If you already have a existing repository but there is a new branch that is yet listed do a:

git fetch

If you just want to take a quick peek at an upstream branch, you can check it out directly:

$ git checkout origin/experimental

But if you want to work on that branch, you'll need to create a local tracking branch:

$ git checkout -b experimental origin/experimental

Now, if you look at your local branches, this is what you'll see:

$ git branch
  master
* experimental

You can actually track more than one remote repository using git remote.

$ git remote add win32 git://example.com/users/joe/myproject-win32-port
$ git branch -a
* master
  origin/HEAD
  origin/master
  origin/v1.0-stable
  origin/experimental
  win32/master
  win32/new-widgets 

At this point, things are getting pretty crazy, so run gitk to see what's going on:

$ gitk --all &

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment