"Git"ting Smarter: Enter Git Aliases

"Git"ting Smarter: Enter Git Aliases

ยท

2 min read

Git aliases Revelation in the lecture hall

I've been navigating the command line for decades, using shell aliases, but I just learned about Git aliases ๐Ÿคฆโ€โ™‚๏ธ While waiting for Demis Hassabis' lecture to begin, I was watching a whiz kid zipping through Git commands: "g this", "g that". "Wait a minute... what wizardry is this?"

For those as blissfully unaware as I was until yesterday, Git aliases are about turning those often-typed commands into short versions. Like turning git commit -m into a friendly g done, so you can save those extra keystrokes for your next epic code.

Setting Them Up

Setting up these aliases is easy. Just a couple of commands in the terminal git config --global alias.unstage 'reset HEAD --โ€™ or a quick edit in your .gitconfig file, and you're setup. Here are some aliases you might consider:

AliasCommandDescription
ststatusShow the working tree status.
cocheckoutSwitch branches or restore working tree files.
brbranchList, create, or delete branches.
cmcommitRecord changes to the repo.
plpullFetche from and integrate with another repo or a local branch.
pspushUpdate remote refs along with associated objects.
dfdiffShow the changes between commits, commit and working tree, etc.
lglog --graph --oneline --decorate --allShow a decorated log graph in a single line format.
save!git add -A && git commit -m 'chore: savepoint'Add all changes and create a save point commit (here we run multiple git commands using && shell operator)
undoreset HEAD~1 --mixedUndo the last commit, leaving changes in your working directory.
amendcommit --amendAmend the last commit (useful for adding missed files or updating the commit message).
lastlog -1 HEADShow the last commit.
graphlog --graph --pretty=format:'%C(auto)%h%d %s %C(black)%C(bold)%cr' --abbrev-commitDisplays an ASCII graph of the commit history.

The Moral of the Story

There's always something new to learn, some shortcut to discover, or some tool that's been under your nose the whole time.


Embrace the continuous learning journey , stay curious, and happy coding! ๐Ÿ˜‰๐Ÿ‘จโ€๐Ÿ’ป๐Ÿš€

ย