Questions tagged [git-alias]

With aliases, you can avoid typing the same commands over and over again. Aliases were added in Git version 1.4.0.

To show how to use Git aliases, suppose you wish you could write git ci instead of git commit. You can achieve this by adding the following section to ~/.gitconfig:

[alias] ci = commit

Some people are uncomfortable editing the config file themselves. They can edit the config by calling git config alias.ci commit instead.

If you want to have the alias available everywhere on your local machine, you can either - edit ~/.gitconfig, or - use the --global flag:

git config --global alias.ci commit

Read the Git SCM Wiki for technical details.

116 questions
784
votes
26 answers

How do I alias commands in git?

I saw a screencast where someone had gotten git st git ci to work. When I do it I get an error asking me if I meant something else. Being a git newb, I need to know what you have to do to get this done?
DevelopingChris
  • 39,797
  • 30
  • 87
  • 118
245
votes
12 answers

Git Alias - Multiple Commands and Parameters

I am trying to create an alias that uses both multiple Git commands and positional parameters. There are Stackoverflow pages for each, and it would appear painfully obvious to do both, but I am having trouble. As an example, I want to switch to…
Stella
  • 2,453
  • 2
  • 14
  • 5
174
votes
3 answers

How to alias 'git checkout' to 'git co'

I'd like the command git co to be the same as typing git checkout. A normal Bash alias (alias co='checkout') doesn't work.
joseph.hainline
  • 24,829
  • 18
  • 53
  • 70
78
votes
4 answers

Pass an argument to a Git alias command

Can I pass arguments to the alias of a Git command? I have some alias in Git config, like so: rb1 = rebase -i HEAD~1 rb2 = rebase -i HEAD~2 rb3 = rebase -i HEAD~3 rb4 = rebase -i HEAD~4 .... Is it possible to make an rb alias so that git rb
HaveF
  • 2,995
  • 2
  • 26
  • 36
48
votes
8 answers

Force push current branch

I often rebase feature branches and then want to force push them to the server. git push --force origin feature-mongodb-support Is there any shortcut for git push --force origin ?
iblue
  • 29,609
  • 19
  • 89
  • 128
16
votes
3 answers

git alias to delete local and remote

I'm trying to write an alias to delete both a local and remote branch at the same time, but I can't figure out why the syntax is not working. In ~/.gitconfig, I've tried the following aliases, but each produces the same result, which is…
biegel
  • 570
  • 5
  • 12
15
votes
2 answers

What is the meaning of the "bang" or "!" before the git command?

As you can see from this excerpt, there is a "!" before the git command. What's the point? [alias] commitx = !git add . && git commit - https://stackoverflow.com/a/8956546/1354543 I understand aliases and what the command itself is doing, but not…
Joe Collins
  • 458
  • 3
  • 12
12
votes
3 answers

Git config alias escaping

I'm trying to write a git alias that removes from the commit messages the string "[ci skip]" (placed at the end of the message), but I'm having problem with escaping. The alias takes all the commit from the one passed as argument to HEAD. If I run…
se7entyse7en
  • 4,310
  • 7
  • 33
  • 50
11
votes
1 answer

Git completion for alias as if for Git itself

Background I have successfully configured Bash completion for various Git aliases. For example: $ git config alias.subject !git --no-pager show --quiet --pretty='%s' $ function _git_subject() { _git_show; } $ git subject my $ git subject…
11
votes
4 answers

Zsh completion for custom git "bang" alias - Git branch name

I have a Git alias update that I would like to outfit with branch-name completion. The alias is defined like so: [alias] update = "!f() { git push . origin/$1:$1; }; f" (It updates a local tracking branch with its upstream version, without…
Ken Williams
  • 22,756
  • 10
  • 85
  • 147
11
votes
1 answer

git commit --amend is dangerous

I sometimes accidentally type git commit -amend when I really wanted to git commit --amend. Git detects that and asks me $ git commit -amend error: did you mean `--amend` (with two dashes ?) which is great. However, sometimes I write git commit…
codingdave
  • 1,207
  • 16
  • 23
8
votes
1 answer

Git alias with two commands (stash pop + merge) executes only the first command. Why? How to execute also the merge?

I set up a git alias like this: git config --global alias.popmerge '!git stash pop && git merge master' Then I call it, like this: git popmerge The "git stash pop" is executed, but the "git merge master" is ignored. If I run "git merge master"…
J. Bruni
  • 20,322
  • 12
  • 75
  • 92
7
votes
2 answers

Is possible to write a multi-line alias in .gitconfig?

I know that is possible to use && (and) statement to go running multiple commands for a same alias. However for long combinations it loses in readability. For example: save = !git status && git add -A && git commit -m \"$1\" && git push --force &&…
artu-hnrq
  • 1,343
  • 1
  • 8
  • 30
7
votes
2 answers

Git: Recursively switching branch (checkout) on all submodules

I'm working on a git repo that contains submodules. I've got branches by the same name (like master, development..) in all submodules (including parent module) and they all track their corresponding remote branches. I'd like to have same branches…
y2k-shubham
  • 10,183
  • 11
  • 55
  • 131
7
votes
2 answers

Should I use `sh -c \"...\"` or `"!f() {... ; }; f" in git alias scripts?

I've been getting my feet wet in writing git aliases that take arguments. I've seen some people running shell scripts with [alias] shAlias = !sh -c \" ... \" and others running functions with [alias] fAlias = "!f() { ... ; }; f" It seems like…
henry
  • 4,244
  • 2
  • 26
  • 37
1
2 3 4 5 6 7 8