Git Tips & Tricks
Zilong HE edited this page 2026-11-10 15:41:03 +08:00

Git Rebase

Basics

We want a linear Git history, which is why you can't have any merge commits in Pull Request. To keep you branch up-to-date (or get rid of the merge commit), use Git rebase instead of merge.

To update your branch or your master - assuming origin points to your fork and upstream to the offical CP2K repository, add the --rebase parameter to the git pull call:

$ git pull --rebase upstream master

If you have pushed this branch already to your fork on a remote side (GitHub most likely), you then have to use force-push since the commits changed:

$ git push --force

Resolving conflicts

When resolving conflicts during a Git Rebase you have to keep in mind that when Git refers to changes as theirs or remote, this is actually what you have in the branch you are rebasing.

So, when running a mergetool using

$ git mergetool

the right pane (the file is called *.REMOTE) is how the file looked after the current commit before the rebase, the left how it currently looks in master and the middle pane shows you its new content after this rebase.

If you know that you want to take all your changes (for example because you've created the file in this branch but you ran the prettifier in a previous commit in this rebase, therefore breaking your own commits), you can do:

$ git checkout --theirs -- path/to/your/file

Likewise: if you know you want to discard your changes to a specific file in this commit, use --ours instead.