Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My current .gitconfig aliases
[alias]
co = checkout
cob = checkout -b
coo = !git fetch && git checkout
br = branch
brd = branch -d
brD = branch -D
merged = branch --merged
st = status
aa = add -A .
cm = commit -m
aacm = !git add -A . && git commit -m
cp = cherry-pick
amend = commit --amend -m
dev = !git checkout dev && git pull origin dev
staging = !git checkout staging && git pull origin staging
main = !git checkout main && git pull origin
master = !git checkout master && git pull origin
po = push origin
pu = !git push origin `git branch --show-current`
pod = push origin dev
pos = push origin staging
pom = push origin main
poh = push origin HEAD
pogm = !git push origin gh-pages && git checkout master && git pull origin master && git rebase gh-pages && git push origin master && git checkout gh-pages
pomg = !git push origin master && git checkout gh-pages && git pull origin gh-pages && git rebase master && git push origin gh-pages && git checkout master
plo = pull origin
plod = pull origin dev
plos = pull origin staging
plom = pull origin main
ploh = pull origin HEAD
unstage = reset --soft HEAD^
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
f = "!git ls-files | grep -i"
gr = grep -Ii
la = "!git config -l | grep alias | cut -c 7-"
@johnpolacek

This comment has been minimized.

Copy link
Owner Author

@johnpolacek johnpolacek commented Oct 19, 2014

@qbunt

This comment has been minimized.

Copy link

@qbunt qbunt commented Oct 20, 2014

thanks for sharing these man, there are some gems in here 👍

@theskillwithin

This comment has been minimized.

Copy link

@theskillwithin theskillwithin commented Oct 2, 2016

trying to figure out how to have my gh-pages be a build folder inside the repo that is .gitignored from other branches.

breaks on gitignore

git push --force origin $(git commit-tree -m "auto" master:dist):gh-pages

hmmm

tree="$(export GIT_INDEX_FILE="$(mktemp)"; cat .git/index >"$GIT_INDEX_FILE"; git add -f dist && git write-tree --prefix=dist)"
    after that, imo you should do something like 
    git update-ref refs/heads/gh-pages "$(git commit-tree -p gh-pages -m auto "$tree")"
@JamesLaneProgramming

This comment has been minimized.

Copy link

@JamesLaneProgramming JamesLaneProgramming commented Feb 8, 2018

I have attempted to create a repository using curl and the RESTful Github API, The libcurl command works in the bash shell but not as an alias could somebody help me with this? Sorry in advance for necro'ing an old post but it is the most relevant to the work i am doing :)

create = !curl -H 'Authorization: token <My_Access_Token>' -d '{ "name": "<Repo_Name>", "private": false }' https://api.github.com/user/repos

Before anyone asks, Yes i have interchanged <My_Access_Token> with my actual developer token, same with <Repo_Name>

@chamur

This comment has been minimized.

Copy link

@chamur chamur commented Aug 14, 2018

Thanks for sharing!

@Alfredynho

This comment has been minimized.

Copy link

@Alfredynho Alfredynho commented Feb 2, 2019

Gracias por compartir tu configuracion

@hopeseekr

This comment has been minimized.

Copy link

@hopeseekr hopeseekr commented Mar 21, 2019

A SUPER valuable one I use EVERY DAY as team lead both for myself and others, is:

    redate = rebase --committer-date-is-author-date

After a rebase, when you run it, it resets all of the commit dates to the author dates so your commit logs on github / gitlab show up in proper chronological order, instead of the moment of the rebase.

To use, when you're in a feature branch:

git rebase origin/master
@qins

This comment has been minimized.

Copy link

@qins qins commented Sep 11, 2019

dmerged = "git branch --merged | grep -v '\*' | xargs -n 1 git branch -d"

missing "!" ?

should be:

dmerged = "!git branch --merged | grep -v '\*' | xargs -n 1 git branch -d"

or better use egrep -v '(^\*|master|dev)' to avoid accident

@johnpolacek

This comment has been minimized.

Copy link
Owner Author

@johnpolacek johnpolacek commented Sep 13, 2019

@qins I decided to remove that one altogether as I never use it.

@adrianohrl

This comment has been minimized.

Copy link

@adrianohrl adrianohrl commented Nov 13, 2019

I have attempted to create a repository using curl and the RESTful Github API, The libcurl command works in the bash shell but not as an alias could somebody help me with this? Sorry in advance for necro'ing an old post but it is the most relevant to the work i am doing :)

create = !curl -H 'Authorization: token <My_Access_Token>' -d '{ "name": "<Repo_Name>", "private": false }' https://api.github.com/user/repos

Before anyone asks, Yes i have interchanged <My_Access_Token> with my actual developer token, same with <Repo_Name>

@JamesLaneProgramming , have you solved this problem? I'm trying to create the following alias (in the ~/.gitconfig file) for getting the default Python's .gitignore file:

[alias]
      ...
      ignore_python = "!wget -O ./.gitignore https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore"
@weibangtuo

This comment has been minimized.

Copy link

@weibangtuo weibangtuo commented Nov 19, 2019

Share

pu = !git push origin `git branch --show-current`

Push current branch to origin with the same name.

@martinmana

This comment has been minimized.

Copy link

@martinmana martinmana commented Apr 2, 2020

Hi!
I've been looking for days for a fetch+checkout (to the new branch) alias, couldn't find it. And I'm not experienced enough to write it myself.
All the time I'm doing

git fetch origin master:examplename
And then
git checkout examplename

Can any of you guys give me a hand?
Cheers

@weibangtuo

This comment has been minimized.

Copy link

@weibangtuo weibangtuo commented Apr 2, 2020

@martinmana

coom = "!f() { git fetch origin master:\"$1\"; git checkout \"$1\";}; f"

usage: git coom examplename

@martinmana

This comment has been minimized.

Copy link

@martinmana martinmana commented Apr 2, 2020

Thank you very much @weibangtuo . I would love to know all this stuff. That's amazing. I really appreciate this.
Again, I'm really new to all this world.
Is there any chance you could write exactly the command for me to create this alias? Like... exactly. I keep getting this
-bash: !f: event not found

Thank you in advance. Regards

@weibangtuo

This comment has been minimized.

Copy link

@weibangtuo weibangtuo commented Apr 2, 2020

@martinmana
you can edit gitconfig file vi ~/.gitconfig and add line to [alias] section.

or command

git config --global alias.coom "\!f() { git fetch origin master:\"\$1\"; git checkout \"\$1\";}; f"
@johnpolacek

This comment has been minimized.

Copy link
Owner Author

@johnpolacek johnpolacek commented Apr 2, 2020

@martinmana

You could change the co to always do a full fetch first. I don't see what that would hurt.

co = fetch && checkout
@innyso

This comment has been minimized.

Copy link

@innyso innyso commented Apr 18, 2020

thank you for the great list of git alias!G

@jtomaszewski

This comment has been minimized.

Copy link

@jtomaszewski jtomaszewski commented Jun 17, 2020

Any idea how to make those aliases to work with both master and main branch names? So that for example if main branch exists, pom pushes to main, if not, it pushes it to master.

@danielturus

This comment has been minimized.

Copy link

@danielturus danielturus commented Sep 14, 2020

pu = !git push origin git branch --show-current

Thanks for this one!

@rantoniuk

This comment has been minimized.

Copy link

@rantoniuk rantoniuk commented Nov 5, 2020

pu is simpler via git push -u origin HEAD :-)

@fan-tom

This comment has been minimized.

Copy link

@fan-tom fan-tom commented Nov 24, 2020

  update = "!fn() { \
    repo=${2:-origin}; \
    if [[ $(git rev-parse --abbrev-ref HEAD) = \"$1\" ]]; \
    then \
        git pull \"${repo}\"; \
    else \
        git fetch \"${repo}\" \"$1\":\"$1\"; \
    fi; \
    }; fn"

update master without checkout: git update master
update develop from upstream remote: get update develop upstream

@ryansully

This comment has been minimized.

Copy link

@ryansully ryansully commented Jul 12, 2021

@jtomaszewski

Any idea how to make those aliases to work with both master and main branch names? So that for example if main branch exists, pom pushes to main, if not, it pushes it to master.

git symbolic-ref refs/heads/master refs/heads/main will alias master to main. Not quite the answer I think you were looking for, but it should work.

@jtomaszewski

This comment has been minimized.

Copy link

@jtomaszewski jtomaszewski commented Jul 15, 2021

I have following alias now: main = !git symbolic-ref refs/remotes/origin/HEAD | cut -d'/' -f4

git main returns main or master or any other default branch name for the origin/HEAD.

Then I use it in my aliases like this:

  com = "!f(){ git checkout $(git main) $@;}; f"

Which for example is an alias for checking out the default branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment