Reputation: 8622
For example, I have these branches:
local remote
master -> origin/master (other users will update)
develop -> origin/develop (other users will update)
And as of now, master/develop are pointing to same commit
Say I only have a README file and its content is master
1, I do following
$ git checkout develop
$ echo 'develop' >> README && git commit -am 'aaa'
Question:
Suppose no other one changes origin/develop
, no matter which branch I am in,
git push origin develop
will push local develop
to origin/develop
?
2, After 1, become this:
local remote
master (README: master) -> origin/master (README: master)
develop(README: develop) -> origin/develop (README: develop)
Next, someone changed origin/develop:README to other develop
local remote
master (README: master) -> origin/master (README: master)
develop(README: develop) -> origin/develop (README: other develop)
So if I do
A. [in develop branch] $ git pull origin develop
my local develop:README will become other develop
B. [in master branch] $ git pull origin develop
my local develop:README will not change but my local master:README will become other develop
???
so git pull origin develop
does not mean pull origin/develop
to local/develop?
It means pull origin/develop
and merge into current branch ????
So how to pull origin/develop
to local develop
when I am in other branch?
git pull
will update local master to origin/master
and local develop to origin/develop
, is that right? Upvotes: 1
Views: 236
Reputation: 34034
no matter which branch I am in, git push origin develop will push local develop to origin/develop ?
Right.
So how to pull origin/develop to local develop when I am in other branch?
git pull
= git fetch
+ git merge
You can git fetch
- this will fetch all changes from the remore repo to your local tracking branches (eg origin/master
, origin/develop
).
But you cannot git merge
into a noncurrent branch because during merge conflicts may arrise and you won't be able to fix them unless the branch is current.
If you are working on master and you want to set your work aside, merge develop branch and then continue your work on master, you can do the following:
git stash
git co develop
git pull
<resolve conflicts if any>
git ci
git co master
git stash apply
where ci=commit, co=checkout.
git pull will update local master to origin/master and local develop to origin/develop, is that right?
It will fetch both, but merge only the current branch.
Update: As an illustration to @torek's comment to the question, here's a more precise scheme. Actually there're more branches than you've drawn:
local repo remote repo
local branch remote tracking branch local branch
master (README: master) origin/master (README: master) <-> master (README: master)
devel (README: devel) origin/devel (README: devel) <-> devel (README: devel)
Usually the centeral repo ('remote repo' in this scheme) is created without a working tree (git init --bare
) so it doesn't have remote branches, only local ones.
Now
git push:
local repo remote repo
local branch remote tracking branch local branch
master (README: master) ---------------------------------> master (README: master)
git fetch:
origin/master (README: master) <-- master (README: master)
git merge:
master (README: master)<-origin/master (README: master)
and finally, git pull
= git fetch
+ git merge
Upvotes: 1