0

I am trying to understand how to keep my fork's master updated with the original repo's (from which I forked) master.

I read two documents:

Both documents provide more or less these steps:

git fetch upstream
git checkout master
git merge upstream/master

Can these 3 steps be safely reduced to:

git checkout master
git pull upstream/master
  1. If yes, is there any scenario where the reduced two-step update would lead to problems but the three-step update would not?
  2. Can these two steps be reduced to just one step?
pygo
  • 1
  • 2
  • You could consider [reducing it to zero steps](https://stackoverflow.com/a/48085113/2303202) – max630 Feb 19 '18 at 09:48

2 Answers2

0

I just tested it locally, and it seems to be working fine.

git checkout master
git pull upstream master

This will pull the master branch from repository specified by upstream, and merge it with the current branch you're on. If there are any conflicts you will be prompted to solve it manually.

I currently cannot think of any scenario where the two-step version will lead to any problem, provided that you're following the good practice of never committing to master branch of a forked repository. It's quite convenient and does the same thing as the three-step version.

For the last question, I'm afraid no (or conditionally). You need to switch to the master branch before merging upstream/master into your working tree, or it will lead to other problems. The condition is when you're always on branch master and never do any commits to it, you can omit the checkout step.

iBug
  • 35,554
  • 7
  • 89
  • 134
0

As iBug pointed out, there's no single command to update your branch, but you could create an alias:

[alias]
    update = !git rev-parse --verify refs/heads/$1 && git checkout $1 -- && git pull origin $1

Now if you git update master it will switch you to the master branch, and pull origin/master into your branch.

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187