I have two below branches in my remote GitHub repository:
master
test-branch
I did git pull
in my test directory but I don't see any code pull in my local directory. Also when I do git branch
I don't see any local branch listing here. Not sure why? But once I do git branch -a
, see below remote branches displayed in red:
remotes/origin/master
remotes/origin/test-branch
When I do specific branch pull ie git pull origin test-branch
I see code gets pulled in my test directory but when I do git branch
I see below listing:
* master
remotes/origin/test-branch [displayed in red]
Not sure why it is displaying master here as I pulled test-branch code. Also how I can see which remote branch this master is pointing to?
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.
git fetch
git checkout --track origin/test-branch
This will basically do the following:
git fetch
will update to remote test-branch
origin/test-branch
as remote tracking branchorigin/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
.
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.
By default, git pull origin xyz
runs git fetch origin xyz
followed by git merge FETCH_HEAD
. It is important to note that the specified remote branch is not checked out but integrated into the local branch.
It displays * master
because you actually did not switch to a different branch by running git pull origin xyz
. However, the changes of the branch xyz
were integrated into your local master
branch since a merge was performed after fetching. Probably you want to first switch to the desired branch ( git checkout xyz
) and then pull the changes ( git pull
).
You can use git branch -a -vv
to show remote and local branches including tracking information as well as the currently checked-out branch:
* xyz b7b2f7c [origin/xyz] Commit Message A
main 8c4124b [origin/main] Commit Message B
remotes/origin/HEAD -> origin/main
remotes/origin/xyz b7b2f7c Commit Message A
remotes/origin/main 8c4124b Commit Message B
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.