Skip to main content

Merge, Rebase

merge vs rebase

https://www.atlassian.com/git/tutorials/merging-vs-rebasing

Make the current Git branch a master branch

git checkout better_branch
git merge --strategy=ours master    # keep the content of this branch, but record a merge
git checkout master
git merge better_branch             # fast-forward master up to the merge

rename branch (local and remote)

  • git branch -m master main - rename master to main
  • git push -u origin main - push branch with new name
  • set remote default branch in remote repo.
  • protect new brunch, unprotect old branch (in remote repo)
  • git push origin --delete master - delete branch in remote repo

mergetool

  • installed merge tool like meld necessary
    • sudo apt install meld
    • configure it: https://stackoverflow.com/questions/34119866/setting-up-and-using-meld-as-your-git-difftool-and-mergetool
[diff]
    tool = meld
[difftool]
    prompt = false
[difftool "meld"]
    cmd = meld "$LOCAL" "$REMOTE"
    
[merge]
    tool = meld
[mergetool "meld"]
    # Choose one of these 2 lines (not both!) explained below.
    cmd = meld "$LOCAL" "$MERGED" "$REMOTE" --output "$MERGED"
 #   cmd = meld "$LOCAL" "$BASE" "$REMOTE" --output "$MERGED"
  • merge
    git checkout master
    git merge branch_name
    
  • start mergetool: git mergetool

merge (force remote)

  • drop local changes (incl commits)
git fetch --all
git reset --hard origin/master
```