Many open source users love a good Bash alias and are usually happy to show off a particularly robust .bashrc file when given the chance. If you're a frequent user of Git, you might benefit from a few Git aliases mixed in with your other Bash aliases. Alternately, you can create aliases specific to Git with this
git config command. This example sets the
git co command to
$ git config --global alias.co checkout
I asked our contributors for their favorite and most useful Git aliases so that you could take advantage of their ideas. Here are their suggestions.
Here's an easy way to see just the most recent log entry:
git config alias.last 'log -1 HEAD'
Opensource.com author Sachin Patil uses
hist for reviewing logs:
log --pretty=format:'%h %ai [%an] %s%d' --graph
Sachin creates this Bash alias for pull requests:
# github pull request. # Usage: git pr <REMOTE> <PR_ID> <branch> pr="\!sh -c 'git fetch $1 pull/$2/head:$3 && git checkout $3' -"
git diff command is helpful for all kinds of comparisons, but sometimes all you really want is the file name of what's changed. Kristen Pol creates an alias to shorten the
git diff --name-only
Kristen says, "We typically have a lot of development happening simultaneously, so knowing the most recent commit across all branches is handy." Here's a command Kristen aliases for that purpose:
git branch --remotes --verbose --sort=-committerdate
Everybody appreciates a fresh start. This is Kristen's alias for wiping out a branch, leaving it fresh and clean:
alias gitsuperclean='git reset --hard; git clean --force -d -x'
Custom filter-repo command
Chris explains the alias. "Ever want to pull a specific directory out of a larger Git repository and make it its own, separate repo, while keeping all the Git history? That's exactly what filter-repo does."
What Git command do you use so often that you alias it? Do you use Bash aliases or Git aliases, or a mix of both? Tell us in the comments!