Git: automatically stash while rebasing or merging with autostash
Imagine you’re part way through making some changes, and you realize that you need to rebase or merge. You can:
(All tags.)
Imagine you’re part way through making some changes, and you realize that you need to rebase or merge. You can:
To errr is human, to undo computer can help.
You started a new branch, worked hard on initial commits, and you’re ready to send it for review. You try to push and:
Git hosts offer a “squash merge” option that merges a reviewed branch by combining all its commits into one. This leads to a linear Git history on your main branch, which is easier to understand and refer back to code reviews.
The Git community is gradually moving the default branch name from “master” to “main”, because the term “master” is hurtful to some people as it refers to slavery.
By default, if you mistype a Git command, it will list similar commands that you might have meant:
You can use git rev-parse to show the SHA of the current Git commit:
--update-refsWhen working on a feature, you might split it into several stacked branches, so you can merge each one separately. But updating such branches can be annoying since you have to manage them independently. Git 2.38 (2022-10-15) made this management easier with the new --update-refs option, which can rebase a stack of branches at once. Let’s look at a couple of examples.
Projects often accumulate an amount of unused code. This cruft makes a prjoect harder to navigate, and can confuse future development or debugging.
--keep-baseWhen you have a long-lived feature branch with many “work in progress“ commits, it can become tiresome to rebase it onto your main branch due to conflicts. You can end up fixing conflicts in the same areas of the same files over and over for multiple commits.
Occasionally it’s useful to run commands on all files in your repository, or those matching a pattern. This is possible by combining git ls-files and xargs.
git diffOnce in a while, I have to make a change to many or all of my blog posts. For example, implementing opengraph meta tags.
I recently add a pre-flight check to a devops project to ensure that all commits from the Git repository’s origin/master are present locally. This is to guard against developers accidentally reverting others’ deployed changes.