As an example assume you want to write a git alias, which shows the difference between the current branch and its origin
partner.
In the specific case of master it would look like the following:
[alias]
top = log --oneline --graph --decorate master ^origin/master
How to replace master
?
However, if you’re working on the same branch name as the one you wish to push changes to, then we can alias the remote branch name as HEAD . Push your commits from the local git repository to the origin or upstream remotes with a shortcut as simple as git done using this alias:
And to list all of your local branches, you use the git branch command. To collaborate with other developers on the same project and for them to view any changes you make, you need to push changes from your local branch to a remote repository. This leads us to remote branches. A remote branch refers to a branch that exists in a remote repository.
Your git aliases are often stored per your user’s configuration at ~/.gitconfig. You can also manually set aliases using, for example, the command git config alias.s ‘status -s’.
Use the following git alias to have a shortcut for it: Moving back and forth between git branches is also something we often do. Let’s shorten that! In fact, a git branch checkout can be done using a shortcut, such as git checkout - which checks out the previous branch you were on.
If your git version is not ridiculously old, the string @{u}
means "upstream", i.e., whatever origin/foo the current branch is tracking. (And: HEAD
means "the current branch, if on a branch", and omitting something in the ..
syntax means HEAD
.) Thus, @{u}..
means "everything in HEAD that is not in its upstream":
[alias]
top = log --oneline --graph --decorate @{u}..
One way to do it:
[alias]
top = "!git log --oneline --graph --decorate `git rev-parse --abbrev-ref HEAD` ^origin/`git rev-parse --abbrev-ref HEAD`"
Which turns alias into a shell command, which gives you an ability to nest commands.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With