While Git supports aliases and I am a big fan of Git aliases, (e.g. ‘git lg’), the most valuable to me (and most used) aliases are shell aliases (e.g. ‘gc’ for ‘git commit’).
Git
Git Rebase and the Multiverse
In “Git Merge and the Multiverse” I looked at merging branches and how sometimes this results in a fast-forward merge and sometimes in the creation of a merge commit. Now let’s look at Git rebase (a.k.a. the power to rewrite history).
Git Merge and the Multiverse
If you’re a fan of science (or science fiction), you may be familiar with the concept of the “Multiverse”, the idea that there are multiple universes. In some science fiction stories, one universe can split, branching into multiple universes and then later collapse into a single universe, this is a surprisingly good analogy for Git and branching.
Set Number of Characters in Commit Hash for git log
When I’m writing examples, it is often nice to have very short commit hashes. The ‘–abbrev=3’ argument, passed after the ‘–oneline flag, allows me to reduce the number of characters in the commit to 3.
Git delete remote branch
This is the command I run when I want to delete a branch named “chore/fix-typo” from the default remote (which is named “origin”): git push origin –delete chore/fix-typo
Git Get Current Branch Name
I find there are two different times I want to get the current branch name: 1. When I’m at the command line, 2. Inside a Git alias function I’m writing. Interestingly, I find that my approach in these two situations are different.
Git Branch Naming
There are lots of ways to name Git branches. These are my personal rules I’ve developed for naming Git branches.
Replace Local Git Branch with Remote Version
This situation often arises for me when I’m reviewing a teammate’s Pull Request and they make changes by rewriting history. In this situation, I want to discard my local copy of the Pull Request branch and replace it with the version on GitHub (or wherever the remote branch is being stored).
Git autoSetupRemote Prevents “no tracking information” Error
After creating a pushing a new branch to GitHub (or any remote), when I do “git pull” I often get an error that says “There is no tracking information for the current branch”. The Git config value “autoSetupRemote”, introduced in Git version 2.38, lets us avoid this entirely error.
Compare composer.json on Two Different Git Branches
I have composer.json files on two different branches and I want to compare their (non-dev) dependencies. This is the command I run to compare the “require” section of composer.json on my current branch to the “require” section of composer.json on another branch.