# Git aliases

Published articles for Git aliases.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Simplify & replace git-number with git aliases

DevFeed: [Simplify & replace git-number with git aliases](<https://devfeed.tech/articles/simplify-replace-git-number-with-git-aliases-25251.md>)

Original publisher: [Read original article](<https://kau.sh/blog/git-alias/>)

Author: Kaushik Gopal

Published: 2024-01-27T20:00:00Z

Content type: tutorial

Language: en

Sources: [Kaushik Gopal's Site](<https://devfeed.tech/sources/kaushik-gopal-s-site.md>)

Topics: [Git](<https://devfeed.tech/topics/git.md>), [Shell](<https://devfeed.tech/topics/shell.md>), [Perl](<https://devfeed.tech/topics/perl.md>)

Tags: [aliases](<https://devfeed.tech/tags/aliases.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [git](<https://devfeed.tech/tags/git.md>), [git-aliases](<https://devfeed.tech/tags/git-aliases.md>), [perl](<https://devfeed.tech/tags/perl.md>), [shell](<https://devfeed.tech/tags/shell.md>), [simplify](<https://devfeed.tech/tags/simplify.md>), [unix](<https://devfeed.tech/tags/unix.md>)

### AI overview

The author replaces git-number, a Perl tool they considered more than their use required, with Git aliases to avoid installing an extra dependency. A simple `git add` alias uses `git status --porcelain` and shell text processing to select a file by its position in the status list. The author says a later, more complex alias also handles adding all files with no argument or `.`, and selecting numbered ranges such as files 2-3 or 3-5. They favor keeping the working command in `.gitconfig` rather than maintaining a separate script. The excerpt does not include the complete final alias or all command details.

### Source excerpt

I wrote a blog post about git-number and how useful it was for my command line git usage. In an on-going effort to simplify my lifestyle & setup, I replaced git-number with a few git aliases. I'll explain how I recreated the functionality in this blog post. Why replace it? ## Looking at git-number's source I realize it is written in Perl. I'm not here to cast judgement on another programming language but reading the code, it felt like overkill for my use cases. It also meant I could eliminate one additional 3rd party library that I have to install every time. Let's go ahead and recreate it with some good old unix command line fu. Building git add <number> # To git add the first file, I have to manually type the entire path git add 0.collapse-categories-into.... This is tedious and error-prone. If your file is nested in a series of directories (like an Android or iOS app), it becomes worse. With git-number, this is as simple as git-number add 1 # where 1 stands for the order # in which a file shows up in git status Let's recreate that with a git alias. # in your .gitconfig file [alias] a = !"a() { <UNIX COMMAND GOES HERE> ; }; a" The key now is to come up with a unix command that will take in a number and pluck that file for you. Here's a simple version of that command: You can now make it a git alias by adding it to your .gitconfig file: # .gitconfig [alias] a = !"a() { git add $(git status --porcelain | cut -b4- | sed -n \"$1p;$1q\"); }; a" You can systematically recreate all of the git-number functionality in pure git aliases! Bonus tweaks # Over time, I've tweaked the above command to a behemoth shell command that accounts for a variety of use cases: g a - git add all files g a . - git add all files g a 2-3 - git add second and third file g a 3-5 - git add second to fifth file Here's what my actual alias is, in all its glory: # .gitconfig [alias] a = "!f() { \ if [[ $# -eq 0 || \"$1\" == \".\" ]]; then \ git add .; \ else \ files_to_add=(); \ for arg in $(seq $(g

## Git hacks - a set of my favorite git aliases

DevFeed: [Git hacks - a set of my favorite git aliases](<https://devfeed.tech/articles/git-hacks-a-set-of-my-favorite-git-aliases-27686.md>)

Original publisher: [Read original article](<https://gagor.pro/2024/01/git-hacks-a-set-of-my-favorite-git-aliases/>)

Author: Tom

Published: 2024-01-27T00:00:00Z

Content type: article

Language: en

Sources: [Tomasz Gągor](<https://devfeed.tech/sources/tomasz-gagor.md>)

Topics: [Git](<https://devfeed.tech/topics/git.md>), [bitbucket](<https://devfeed.tech/topics/bitbucket.md>), [Pull Request](<https://devfeed.tech/topics/pull-request.md>)

Tags: [bash](<https://devfeed.tech/tags/bash.md>), [bitbucket](<https://devfeed.tech/tags/bitbucket.md>), [commands](<https://devfeed.tech/tags/commands.md>), [commit](<https://devfeed.tech/tags/commit.md>), [git](<https://devfeed.tech/tags/git.md>), [git-aliases](<https://devfeed.tech/tags/git-aliases.md>), [linux](<https://devfeed.tech/tags/linux.md>), [macos](<https://devfeed.tech/tags/macos.md>), [pull-requests](<https://devfeed.tech/tags/pull-requests.md>)

### AI overview

An overview of the author's favorite Git aliases for simplifying status and log checks, commits, branch management, reverts, and Bitbucket navigation. The article also describes aliases for extracting Jira ticket numbers and managing commit messages.

### Source excerpt

I use Git a lot, even writing this article i will commit text few times. There's a set of aliases I rely on daily and they're first I add in new place. Some Git commands are unnecessarily verbose. You can make your life much easier with bash-completions, but if you write it tens of times per day, it's anyway a lot of typing... and I'm a lazy man 😄 Simple status/log checks git s s = status --short --branch --untracked-files Shows a short, branch-focused status with untracked files.

## Automatically add ticket ID to every commit message in Git

DevFeed: [Automatically add ticket ID to every commit message in Git](<https://devfeed.tech/articles/automatically-add-ticket-id-to-every-commit-message-in-git-27667.md>)

Original publisher: [Read original article](<https://gagor.pro/2021/11/automatically-add-ticket-id-to-every-commit-message-in-git/>)

Author: Tom

Published: 2021-11-09T00:00:00Z

Content type: tutorial

Language: en

Sources: [Tomasz Gągor](<https://devfeed.tech/sources/tomasz-gagor.md>)

Topics: [Git](<https://devfeed.tech/topics/git.md>), [Automation](<https://devfeed.tech/topics/automation.md>)

Tags: [add-ticket-id-to-commit](<https://devfeed.tech/tags/add-ticket-id-to-commit.md>), [automation](<https://devfeed.tech/tags/automation.md>), [bash](<https://devfeed.tech/tags/bash.md>), [commit](<https://devfeed.tech/tags/commit.md>), [commit-message-best-practices](<https://devfeed.tech/tags/commit-message-best-practices.md>), [git](<https://devfeed.tech/tags/git.md>), [git-aliases](<https://devfeed.tech/tags/git-aliases.md>), [git-automation](<https://devfeed.tech/tags/git-automation.md>), [git-commit-message](<https://devfeed.tech/tags/git-commit-message.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [jira-integration](<https://devfeed.tech/tags/jira-integration.md>), [linux](<https://devfeed.tech/tags/linux.md>), [macos](<https://devfeed.tech/tags/macos.md>)

### AI overview

A tutorial explains how to use custom Git aliases to read a ticket ID from the branch name and automatically prefix commit messages with it. Commits fail when no ticket ID is available.

### Source excerpt

Learn how to automatically add ticket IDs to every commit message in Git, ensuring consistent and informative commit history by using custom Git aliases.

## Mining your CLI history for good git aliases

DevFeed: [Mining your CLI history for good git aliases](<https://devfeed.tech/articles/mining-your-cli-history-for-good-git-aliases-19058.md>)

Original publisher: [Read original article](<https://httptoolkit.com/blog/find-best-git-aliases/>)

Author: HTTP Toolkit; Tim Perry

Published: 2020-11-30T13:35:00Z

Content type: tutorial

Language: en

Sources: [HTTP Toolkit](<https://devfeed.tech/sources/http-toolkit.md>)

Topics: [Git](<https://devfeed.tech/topics/git.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Bash](<https://devfeed.tech/topics/bash.md>), [Script](<https://devfeed.tech/topics/script.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [aliases](<https://devfeed.tech/tags/aliases.md>), [cli](<https://devfeed.tech/tags/cli.md>), [git](<https://devfeed.tech/tags/git.md>), [git-aliases](<https://devfeed.tech/tags/git-aliases.md>), [history](<https://devfeed.tech/tags/history.md>)

### AI overview

Use shell history to identify which git commands are worth aliasing: filter history for git commands, sort and count duplicates, then rank by frequency, optionally showing only the top results. The excerpt's example finds frequent commands such as `git status`, `git add -p`, and `git commit --amend`. Exact-line counting misses commands whose arguments vary, such as commits with inline messages. The article addresses this by splitting each history line on spaces and counting only a chosen number of leading parts, revealing common command prefixes despite differing arguments. The method assumes a bash-compatible shell, and the excerpt notes that prefix length requires experimentation and is not perfect.

### Source excerpt

If you use the command-line all day, CLI improvements can add a huge boost to your workflow. One of the simplest ways to improve things is to make your most used commands easier & faster to type, by creating aliases. But which aliases? Which commands are most important for your usage? You can probably guess a couple, but it's hard to know for sure, and there's plenty you'll miss. Fortunately your CLI history already has all the answers, if you just know how to ask. As a software developer I'm going to focus on git aliases here, but this applies equally well to any command-line tools you use heavily. I'm also assuming a bash-compatible shell, but the same concept should translate elsewhere easily enough. The first step is to use history to do some digging and find out what commands you run most frequently. history prints every line you've run recently in your shell, in chronological order. That gives us the data we need, and with a little bash-fu we can start to get some answers. First, what're your most run git commands? history -n | grep git | sort | uniq -c | sort -k1,1nr -k2 That takes your history, filters for git commands, sorts them alphabetically, counts the repeated lines, and then sorts by the repeat count. You can add a | head -n X too, if you'd like to see just the top X results. For me, with a few weeks history on a new laptop, that looks like: 543 git status 272 git add -p 214 git tree 71 git diff 55 git commit --amend 53 git push origin master 32 git checkout -p 30 git reset 27 git stash pop 26 git stash That tells you a bunch about my git workflow already! These are all common commands I'm using frequently, and commands I should very seriously consider aliasing. It doesn't tell the whole story though. How come git commit --amend is so high up, but git commit doesn't appear at all? That's because for many commits I run git commit -m "..." to commit and pass a message inline, so each of those commands is treated as unique, and won't appear in this top l

## Some useful git aliases

DevFeed: [Some useful git aliases](<https://devfeed.tech/articles/some-useful-git-aliases-33368.md>)

Original publisher: [Read original article](<https://timkellogg.me/blog/2011/05/13/some-useful-git-aliases>)

Published: 2011-05-13T00:00:00Z

Content type: tutorial

Language: en

Sources: [Tim Kellogg](<https://devfeed.tech/sources/tim-kellogg.md>)

Topics: [Git](<https://devfeed.tech/topics/git.md>), [Submodules](<https://devfeed.tech/topics/submodules.md>)

Tags: [config](<https://devfeed.tech/tags/config.md>), [git](<https://devfeed.tech/tags/git.md>), [git-aliases](<https://devfeed.tech/tags/git-aliases.md>), [global](<https://devfeed.tech/tags/global.md>), [graph](<https://devfeed.tech/tags/graph.md>), [submodules](<https://devfeed.tech/tags/submodules.md>), [useful](<https://devfeed.tech/tags/useful.md>)

### AI overview

A collection of Git aliases for displaying formatted repository history, pulling updates for a repository and its submodules, and resetting repositories to a clean state by removing changes and untracked or ignored files.

### Source excerpt

Git aliases are a great way to do more with less typing. Our team uses submodules to an extent which can sometimes be confusing. Some of these aliases help to clarify behavior. These are a few of my favorites.git lgThis gives you a nicely formatted semi-graphical log view with users, branches, and remotesgit config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %C(green)%an%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative" git latestThis does a git pull on the current repository as well as all submodulesgit config --global alias.latest '!sh -c "git pull && git submodule foreach \"git pull\""'git virgin (getting to a pure state)This will reset your changes and delete all untracked and ignored files (includes bin/ and obj/ directories)git config --global alias.virgin '!sh -c "git reset HEAD --hard && git clean -fXd && git clean -fd"'git harem (a whole lot of virgins)This does a virgin for your repository as well as all submodulesgit config --global alias.harem '!sh -c "git virgin && git submodule \"git harem\""'