Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when I do git pull origin master in the develop branch?

Tags:

git

pull

Let's say I have a private topic branch called develop with 2 commits ahead of master.

What does git pull origin master do?

Pull everything from the remote master in the local develop and merge it? Pull everything in the local master branch and merge it?

And is there a way to update master from develop without git checkout master first?

like image 612
e-satis Avatar asked Jan 05 '12 17:01

e-satis


People also ask

What happens when we do git pull origin master?

'git pull origin master' will fetch and update only a specific branch called master and origin in the remote repository. Often, the default branch in Git is a master branch, and it keeps updating frequently. A user can use any branch name to pull that branch from the remote.

Does git pull on branch pull from master?

git merge updates the current branch with the corresponding remote tracking branch. Using git pull , you get both parts of these updates. But, this means that if you are checked out to feature branch and you execute git pull , when you checkout to master , any new updates will not be included.

What does git pull do on a branch?

The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. Merging remote upstream changes into your local repository is a common task in Git-based collaboration work flows.


2 Answers

git pull origin master pulls the master branch from the remote called origin into your current branch. It only affects your current branch, not your local master branch.

It'll give you history looking something like this:

- x - x - x - x (develop)    \         /     x - x - x (origin/master) 

Your local master branch is irrelevant in this. git pull is essentially a combination of git fetch and git merge; it fetches the remote branch then merges it into your current branch. It's a merge like any other; it doesn't do anything magical.

If you want to update your local master branch, you have no choice but to check it out. It's impossible to merge into a branch that's not checked out, because Git needs a work tree in order to perform the merge. (In particular, it's absolutely necessary in order to report merge conflicts and allow you to resolve them.)

If you happen to know that pulling into master would be a fast-forward (i.e. you have no commits in your local master branch that aren't in origin's master) you can work around, as described in this answer.

like image 194
mrj Avatar answered Sep 20 '22 15:09

mrj


Once you commit you changes into your branch by using

git add -A git commit -m <message> 

You can then do:

git pull origin master 

into your branch and that will keep your commits on top of the master pull. Your branch will now be even with master + your commits on top. So, you can now do:

git push 

and git will push your changes, together with the master commits into you branch. You can easily then merge that into master on Github.

like image 27
Vlad Avatar answered Sep 22 '22 15:09

Vlad