Search code examples
windowsgitbranching-and-mergingsmartgit

How to merge from upstream branch?


Here is my git setup (we use Git + Atlassian Stash in our corporate network):

upstream:
  master

origin (my fork of 'upstream'):
  master
  branch1 (branch of master, with a few commits on top of it)

clone (local; clone of 'origin'):
  master
  branch1 (ahead of 'origin:branch1' by 1 commit)

What I want to do:

I want to merge upstream:master -> clone:branch1. I know there will be conflicts with this merge (since I changed files in my branch1 that others have changed in upstream). Once this is done I hope to push my changes back to origin:branch1, which will include my 1 commit + latest base from upstream (I want to keep up to date with the master branch, since that's the one I branched from). Along with this I want it to be a rebase, so that the commit history is clean and doesn't spider-web all over the place.

Another note is that I do not use git command line directly. On Windows, I'm using SmartGit, so if anyone knows instructions for that tool that would be most ideal.

How can I properly merge like I have described above?


Solution

  • If no one else has cloned or is working with branch1, you can rebase it on top of master, once you have updated master to upstream/master.

    • First, fetch upstream (SmartGit: Remote/Pull, select "Fetch Only")
    • Then reset master to upstream/master (SmartGit: Local/Reset)
    • Now rebase branch1 on top of master (SmartGit: In the Branches view, you can right-click on a branch like master and select Rebase HEAD to rebase your current HEAD onto the selected branch master)
      Resolve merge conflicts if necessary.
    • Finally push (force the push) of branch1 to origin (SmartGit: In the context menu of the Branches view, you can invoke Push and Push To on local branches).

    enter image description here