Arslan Tabassum
Arslan Tabassum

Reputation: 940

How to pull the latest changes to my current working branch in GitHub?

Suppose I'm in branch 'abc-test'

git pull origin master

Does this merges master branch with my current Branch('abc-test') or do I need to run more commands?

Upvotes: 2

Views: 15727

Answers (2)

Nei Neto
Nei Neto

Reputation: 487

tl;dr:

run git fetch to fetch latest changes, then run git rebase master to update your branch to the latest changes in master.


Now, to answer your question: yes, git pull origin master does merge them.

However, what you probably want is to apply the commits from master to your branch and then reapply yours on top of them.

That's known as a rebase. The git-rebase manual (which you can access straight from the terminal with git rebase --help is full of helpful diagrams to help you understand what the commit graph looks like.

This is one of them:

Assume the following history exists and the current branch is "topic":
             A---B---C topic
            /
       D---E---F---G master

From this point, the result of the following command:

       git rebase master

would be:

                     A'--B'--C' topic
                    /
       D---E---F---G master

If you use git pull, your graph is going to get really messed up really quickly. Especially if you start using it to update local branches with new commits from a remote repo, because then you'd be creating merge commits from a branch to itself, which is unnecessary and often misleading.

Most of these situations can be avoid by running git pull --rebase or simply git pull -r instead of git pull.

Tip: use git log --oneline --graph as frequently as you can so you can get used to your repos' graph and what are the effects of each git command on it.

Note: Be careful when rebasing too deeply. Read the git-rebase manual.

Upvotes: 6

IMParasharG
IMParasharG

Reputation: 1905

  1. git pull origin master will pull changes from the origin remote, master branch and merge them to the local checked-out abc-test branch
  2. may be you will get conflicts then you have to resolve the conflict and commit the change git commit -m"Your commit Message"
  3. If no conflict then skip step 2 go to step 4
  4. then you have to push the change git push

Upvotes: 2

Related Questions