August 18th, 2024

Aliasing Your Git Commands for Maximum Developer Efficiency

The article explains how to boost productivity in Git by creating command aliases, suggesting shortcuts for common tasks and emphasizing the use of the GitHub CLI for efficient pull requests.

Read original articleLink Icon
Aliasing Your Git Commands for Maximum Developer Efficiency

The article discusses how to enhance productivity in Git by creating command aliases. It highlights the repetitive nature of tasks like raising pull requests, committing changes, and pushing branches, which can be streamlined through aliases in the ~/.gitconfig file. Key suggestions include setting up an alias for pushing changes without specifying the branch, using shortcuts for common commands like checkout, add, commit, rebase, and push. The author provides a list of useful aliases, such as `acp` for adding, committing, and pushing in one command, and emphasizes the importance of using the GitHub CLI for creating pull requests efficiently. The article concludes by recommending that users maintain a repository of their aliases to facilitate quick setup in new environments, ensuring a smoother transition if they change jobs or devices.

- Aliasing Git commands can significantly reduce repetitive tasks and improve developer productivity.

- Key aliases include shortcuts for push, checkout, add, commit, and rebase commands.

- The GitHub CLI can further streamline the process of creating pull requests.

- Maintaining a repository of aliases can help in quickly setting up new development environments.

- The article encourages users to customize their Git experience to enhance efficiency.

Link Icon 15 comments
By @darth_avocado - 6 months
If you're interested, Oh my zsh already has git aliases and much more for dev productivity. It also has a really large number of supported plugins.

https://github.com/ohmyzsh/ohmyzsh?tab=readme-ov-file

https://kapeli.com/cheat_sheets/Oh-My-Zsh_Git.docset/Content...

By @_fat_santa - 6 months
I have several git alias that I live by:

ga = git add -A

gc = git commit

gcm = git commit -m

gp = git push

All of these are defined in my zshrc rather than doing it through git config.

By @hooverd - 6 months
Maybe I'm not a rockstar ninja 10x dev, but I've never found typing speed to be a hindrance. I'll usually only go out of my way to alias/script things if they would otherwise involve some clicking around or chaining commands.
By @reddit_clone - 6 months
Somehow my brain doesn't work like that (short aliases).

I usually use long form commands and parameters. I use ZShell history + FZF to get at commands with minimal keystrokes.

Don't really have to remember anything. Some vague snippets will narrow it down really fast.

By @animal_spirits - 6 months
Using lazygit is probably the most efficient way to do git IMO. https://github.com/jesseduffield/lazygit
By @wcarss - 6 months
I like to keep it pretty simple for git aliases, all defined in my shell alias set:

    ```
    s="git status"
    d="git diff"
    c="git diff --cached"
    ```
I have one other, `rb`, which uses a lot of intermediate work to print all the recent branches I've committed to with nice conditional formatting.
By @from-nibly - 6 months
One time I argued with my junior developer for like 30 minutes convinced that `git cp` was a built in command and not an alias. Turns out I had been carrying that alias through 4 different dot files managers and had completely forgotten that I wrote it.
By @hprotagonist - 6 months
By @lispisok - 6 months
Great example of premature optimization. Save seconds per day typing "gc" instead of "git commit"
By @ketzo - 6 months
One of my favorites is gsw=“git switch -“. It switches back to whatever branch you were last on.
By @jeffbee - 6 months
Next up: not even using git, for maximum developer efficiency.
By @Joker_vD - 6 months
Eh. I've only ever aliased "git status -s | awk '$1 == "M" { print $2 }' | xargs -t git add" as "git_add_all": branch switching works well enough in VSCode, "git diff" shows you your commit preview perfectly fine, and shortening "git push" and "git commit" never really felt like a pressing concern.

Actually, no, there is also "git_show_branch" because every time I needed that in the shell, I could never remember the proper incantation. Something to do with rev-parse or something?

By @g4zj - 6 months
I type rather quickly and feel better having fresh knowledge of the actual commands I use.
By @roombarampage - 6 months
thanks, I hate it.

For me, the seconds this saves in typing don't outweigh the annoyance of trying to pair with another developer who only uses their own special aliases.