[Home](https://codefionn.eu/) · [About](https://codefionn.eu/about/) · [GitHub](https://github.com/codefionn)

---

# Useful git stuff

> Useful commands for using git

*Published on 2024-12-14 · [View as HTML](https://codefionn.eu/useful-git-stuff/) · [Auf Deutsch lesen](https://codefionn.eu/nuetzliche-git-befehle/)*

---


**git** has a vast feature set for those, that want to clean up their merge
requests (before and after the review, but not during).

First of: Use the command line tool. For merging other tools may be more
useful, but please don't use anything more than that. 3rd party integrations
are always different, learn the CLI once and be good at git forever.

## List of useful commands

The list below is a list of useful, advanced git commands (so no just `git commit -a -m "msg"`)

| Command                                | Explanation                                            |
|:---------------------------------------|:-------------------------------------------------------|
| git commit --amend                     | Change the last commit (be sure you can change it on   |
|                                        | the remote!                                            |
| git rebase --interactive &lt;ref&gt;~  | With this you can fixup your commit structure from     |
|                                        | the COMMIT-REF to the latest commit on the branch      |
| git reset --soft &lt;ref&gt;           | Remove all commits up to but not including &lt;ref&gt; |
|                                        | and add modified files in staging                      |
| git commit --fix &lt;ref&gt;           | Create a simple commit fixing something in a merge     |
|                                        | request, so you can simply rebase it away in the       |
|                                        | future!                                                |
| git add --patch &lt;file&gt;           | Add only partial changes from a file                   |

## Things you should do

### git rerere

Did you ever get annoyed by rebasing onto the main branch and having to resolve
conflicts, which you have previously resolved?

Enter [**git rerere**](https://git-scm.com/book/en/v2/Git-Tools-Rerere), the
solution to your `git rebase` problems.

---

[Impressum](https://codefionn.eu/impressum/) · [Datenschutzerklärung](https://codefionn.eu/datenschutz/) · [Mastodon](https://c.im/@codefionn)

© Copyright 2022-2026 Fionn Langhans
