When you do git pull origin test-branch
it will actually pull the changes from origin
remote master
branch and merge them into the currently checked out branch.
Checkout remote branch locally and setup tracking
git fetch
git checkout --track origin/test-branch
This will basically do the following:
git fetch
will update to remote
- Create a local branch called
test-branch
- Setup
origin/test-branch
as remote tracking branch
- Set local branch to
origin/test-branch
From the git manual:
-t, --track
When creating a new branch, set up "upstream" configuration. See "--track" in git-branch(1) for details.
If no -b option is given, the name of the new branch will be derived from the remote-tracking branch, by looking at the local part of the refspec configured for the corresponding remote, and then stripping the
initial part up to the "*". This would tell us to use hack as the local branch when branching off of origin/hack (or remotes/origin/hack, or even refs/remotes/origin/hack). If the given name has no slash, or the
above guessing results in an empty name, the guessing is aborted. You can explicitly give a name with -b in such a case.
So this basically means that if your remote branch is called origin/test-branch
it will call your locally created branch test-branch
.
To show which branches are tracked
git status
will show you in the second line what remote it's tracking if it's tracking
git branch -vv
will show you a list of local branches and which remote they're tracking
Checkout this stackoverflow answer for a more detailed answer.