LaVOZs

The World’s Largest Online Community for Developers

'; github - Git workflow after a pull request from a local branch has been accepted upstream - LavOzs.Com

I have gone through all the steps in the article creating-a-pull-request-from-a-fork. The PR has now been merged upstream. What is the best way to proceed and update the github fork (origin) and local repositories?

Currently I delete the branch on the origin, delete the branch locally. Then do a fetch / merge from upstream to local and push back to the fork. It works but feels crude. Any hints or tips appreciated. Thank you.

Local git commands after the PR is accepted. The branch on origin deleted on the website:

git checkout master
git branch -D branch_name
git fetch upstream
git merge upstream/master
git push origin

I prefer:

git fetch --all
git checkout master
git merge upstream/master --ff-only
git push origin

This works if you are doing your work on feature branches and not on your master. So don't commit/push your work on your master. (Also don't merge your work to your master.)

The "ff-only" forces a fast forward merge and so you're sure the masters are in sync without additional (and unwanted) merge commits. Those merge commits are unwanted are they are also not on the upstream.

If you are committing/pushing on your master (would not recommend it), then your delete-master approach is a good strategy, but be aware you could throw away something unwanted! There is no guarantee that all expected commits are in upstream/master when trowing away origin/master.

If you're doing this regularly, I would recommend to create a git alias :)

Related
How to remove local (untracked) files from the current Git working tree
How do I force “git pull” to overwrite local files?
Delete commits from a branch in Git
How do you create a remote Git branch?
Git pull a certain branch from GitHub
How do I delete a Git branch locally and remotely?
How do I push a new local branch to a remote Git repository and track it too?
How can I determine the URL that a local Git repository was originally cloned from?
How can I reconcile detached HEAD with master/origin?
How do I rename a local Git branch?