Creating your own git shortcuts using .gitconfig

I am always playing around with my .gitconfig file. In case you don’t know, it sits in the root of your user folder in windows (not sure where in linux) . Anyway, figured I’d put it here for reference for myself and if anyone finds it helpful. BONUS

So just a quick breakdown of the new git command this .gitconfig will add.

  • git tweak- My favourite, changes your last commit to include any unstaged changes.
  • git up – Is a git push to the equivalent branch on origin
  • git upf – Is same as above but with force (useful for after a tweak)
  • git diff – Gives you a pretty diff of your unstaged changes
  • git ok – Is basically a rebase continue, I use it after correcting conflicts.
  • git renew – Does a rebase to master
  • git lb – Give a list of the last branches on my local git
  • git diff – Nice colourful diff of your changes

You may like different names for your shortcuts, and they are easy to change.


    [user]
    name = Your name
    email = your@email.com.au
    
    [alias]
    
    # Pretty text base branch tree
    lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
    
    # When on master branch, force local master to be the same as origin
    refreshmaster = checkout -B master remotes/origin/master
    
    # pretty diff of changes
    diff = diff --word-diff=color
    
    # After Fixing conflicts - OK to proceed with rebase
    ok = rebase --continue
    
    # Push the current branch upstream to it's namesake branch on origin
    up = push origin HEAD
    # Push the current branch upstream to it's namesake branch on origin with FORCE
    upf = push -f origin HEAD
    
    # Replace NEW stuff from master to my current branch
    renew = pull --rebase origin master
    
    # Track all new changes
    done = add --all :/
    
    # Wip commit
    wip = commit -m 'Work in progress'
    
    # Amend my last commit. This will first add un-staged changes, then do a commit --amend
    tweak = "!f(){ git add --all :/ && git commit --amend --no-edit; };f"
    
    # Give a list of the last branches on my local git
    lb = for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/   

 

Leave a Reply

Your email address will not be published. Required fields are marked *