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)
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]