Skip to content

Instantly share code, notes, and snippets.

@garudareiga
Last active December 26, 2015 22:38
Show Gist options
  • Save garudareiga/7223987 to your computer and use it in GitHub Desktop.
Save garudareiga/7223987 to your computer and use it in GitHub Desktop.
Store basic git commands I use daily

Git Branches

We have two types of branches: local branches and remote-tracking branches. The names of tracking branches are make up of the name of a "remote" followd by "/" and then the name of a branch in that remote repository.

$ git branch
$ git branch -r

These branches are stored locally:

  • .git/refs/heads (for local branches)
  • .git/refs/remotes/ (for remote-tracking branches)

Git Sharing and Updating

Use git fetch & merge instead of git pull:

$ git fetch origin
$ git diff origin/master
$ git merge origin/master

We add a new reposity as a remote to interact with it. If we want to create a local branch based on a remote-tracking branch, we can do with git branch --track or git checkout --track -b.

$ git remote add [alias] [url]
$ git branch --track [branch] [remote]/[branch]
$ git branch -vv

If we have a different branch name in the remote repository, we'd do this with:

$ git push [remote] [branch]:[remote branch]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment