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:
Alias | Command | Description |
st | status | Show the working tree status. |
co | checkout | Switch branches or restore working tree files. |
br | branch | List, create, or delete branches. |
cm | commit | Record changes to the repo. |
pl | pull | Fetche from and integrate with another repo or a local branch. |
ps | push | Update remote refs along with associated objects. |
df | diff | Show the changes between commits, commit and working tree, etc. |
lg | log --graph --oneline --decorate --all | Show 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) |
undo | reset HEAD~1 --mixed | Undo the last commit, leaving changes in your working directory. |
amend | commit --amend | Amend the last commit (useful for adding missed files or updating the commit message). |
last | log -1 HEAD | Show the last commit. |
graph | log --graph --pretty=format:'%C(auto)%h%d %s %C(black)%C(bold)%cr' --abbrev-commit | Displays 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! ๐๐จโ๐ป๐