Search code examples
gitgitlabbranchgit-merge

How to sync origin/not-master with upstream/master


While making my first open source contribution I made the mistake of working on the master branch and submitting it with the merge request. It will probably be a while before that request gets merged but I would like to keep making contributions in the mean time.

My understanding is that I shouldn't keep working on master now that it's been used in a merge request, and that I should create a new branch to be used in the new merge request.

I ran these commands:

git checkout -B new-branch

git fetch upstream

git merge upstream/master

However, the code in the new-branch still shows the latest origin code rather than the latest upstream code.

How can I set up a new branch to work on the upstream repo without affecting the merge request in progress in master?


Solution

  • The new branch contains your latest origin code because your local master was checked-out when the new branch was created.

    Instead, create the new branch by setting upstream/master as start point.

    git checkout -b new-branch upstream/master