11

I realize there are many questions on syncing branches, and the difference between git commands, but I am finding it hard to know what is the correct process for this.

I am the maintainer of a repository on GitHub. One of the members on my team cloned the repo, created a new-feature branch, pushed this new-feature branch into the GitHub repository, and created a pull request to merge it into master. I approved the pull request and merged it into master on the GitHub website.

What is the correct process to pull this 'new master' down to update my local repository so I have my local directory synchronized, cleanly and without re-writing any history?

  1. git pull --> essentially does a git fetch then git merge...into the branch I'm on?
  2. git pull --rebase --> essentially does a git fetch then git rebase ?
  3. git fetch then git merge origin/master --> same as option 1?
  4. git fetch then git rebase origin/master --> same as option 2?
Community
  • 1
  • 1
Alaa Ali
  • 896
  • 1
  • 12
  • 24

1 Answers1

5

git pull or git pull --rebase are the canonical ways to achieve what you need - sync your local branch with the branch it follows on the server.

Generally speaking, if you use pull requests, you don't want to make any direct changes to the master branch - everything should go via branches. This strategy (it's not a technical requirement) is a common methodology that teams around choose. One benefit is that you never have merge issues when pulling master.

tymtam
  • 31,798
  • 8
  • 86
  • 126
  • On which branch should that be executed? Checkout master first, and then? Also, the problem is that it can happen that the branch is deleted on GitHub, so I'm left with a local one not merged and dangling around. – makons Jun 10 '20 at 14:32
  • 1
    @makons `pull` works in the context of the branch that is currently checked out (The fetch part of `pull` downloads all remote branches, but the merge part of pull merges the appropriate remote branch into the currently checkout out branch only) – tymtam Jun 12 '20 at 07:28