简体   繁体   中英

Is the branch after “origin” the local branch or the remote branch?

I am trying to learn git but I am confused about one part. Usually I use:

git pull origin branch_A

to fetch the remote branch. Usually my current local branch is branch_A the branch on the remote repository is also branch_A , so I will get the remote/branch_A -> local/branch_A . But what if I want to get remote/branch_B -> local/branch_A what should I do? What is the real meaning of the branch after origin . It means the remote branch or the local branch? Does this command mean fetch default remote branch to local branch_A or fetch remote branch_A to current local branch ?

In the command

git pull origin branch_A

the origin refers to the remote repository which you have configured in Git. So this will pull changes from the remote branch_A into the local branch which is tracking this remote. On the other hand,

git pull origin/branch_A

will pull the changes from the local version of the origin/branch_A branch which was cached last time you did a pull.

If you really want your local branch_A to track remote branch_B then the following command can do the trick:

git checkout -b branch_A origin/branch_B

If you already have a local branch_A tracking something else (such as remote branch_A ) then you will have to kill the branch first and then recreate it.

The branch after the name of the repository is a remote branch.

It is what the doc says git-pull .

You allways pull over the branch that you are in your local repository.

However, there is another possibility, If you have a local branch tracked with a remote branch, then the command means that you will pull in your current branch what is in the remote branch that is pointed by your local branch tracked.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM