Aliases - What are those
git aliases are just short hand terms for longer commands. For example you can define an aliases which does
pull with rebase as strategy:
git pure instead of
git pull --rebase.
How to defined Aliases
The general pattern looks the following:
$ git config --<scope> alias.<aliasname> <command>
Okay let's go through this real quick:
scope: There are 3 levels. Your repository, your user or your machine. You can define aliases on all of those 3 levels. If you define an aliases machine-wide then every user in every repository can use it.
|local||This will only effect your current repository you are in.
|global||This is the scope of your current (logged in) user. If you define an alias for the global scope you will have access everywhere in every repo when you are logged in. In Windows you will this under %USERPROFILE%/.gitconfig (e.g. C:/Users/your_user/.gitconfig and under
|system||This is the highest scope: machine-wide. Aliases defined here are valid for all users. On Windows it can be found under:
Note: local overrides global and global overrides system.
aliasname: Your new name for the command. See below for some examples. command: The original command
An example would be:
git config --global alias.pure "pull --rebase"
We introduced the command pure which basically does a pull with rebase instead of merge. You can use the command like this:
git pure. We defined it in the global scope. That means I will have access throughout all my repositories.
This command will add an entry to your
... [alias] pure = pull --rebase
So if you want you can also extend just the git config
Overview of my most used aliases
Coming what you are looking for. Here is a list of my most used git aliases:
|pure||pull --rebase||Does a pull with rebase instead of a merge. For me useful when working on shared branches.||
|co||checkout||Does just a checkout. You can also use
|cm||commit -am||Includes all currently changed files in this commit and creates a commit with the given message.||
|cma||commit --amend --no-edit||This will amend the current commit to the last one and use the commit message of the last commit. Useful if you missed something (like a typo) and don't wanna have a new commit. DANGER: You are rewriting the history. Don't do this on public / shared branches. Your co-workers will hate you for that! If so please always use
|pushu||push -u origin HEAD||This pushes your branch to
|recent||! git reflog | grep -Po "checkout: moving from .to\s(\K.)" | awk '!x[$0]++' | head -5||This one is a bit special. Basically it prints you out the last 5 branches you worked on. Sometimes I have to change my branches quite often and forgot where I was.||