Git Weekly 1 - spring clean-up

| 1 min read

📋 Summary

This week, I had to clean up a git repository that had aged badly.

How to count the number of commits between 2 git branches? #

On this git repository, branch creation was chaotic. So much so that reading the history tree was not easy. In order to estimate the work required to rebase branches, I wanted to know the number of commits they contained. The git rev-list command lists all ancestor commits from a given commit. It is possible to exclude commits accessible from another commit using the ^commit notation.

Here’s the command I used to count all the commits between branch-1 and branch-2:

git rev-list --count branch-2 ^branch-1

How to push a branch to a remote git repository with a different name? #

After rebasing a branch with a large number of commits that I’d never worked on before, I didn’t want to overwrite the original branch. Just in case… When it came to pushing the rebased branch, I decided to rename it. This can be done with a single command:

git push origin my-branch:my-branch-rebased-master

Want to learn more about git? Check out the Git Weekly series!