Tuesday 17 November 2015

Git Aliases

Git Aliases

You can add extra git commands in the command line to make your life easier using git alias

if you type git config --global -e you will be able to edit these.

they should go inside the [alias] section (add one if it's not there)

Basic Commands

These commands are just simple aliases for anything that I use a lot, mainly because I have to type less to use them.

s = status

See the status of the repository

c = commit

Commit changes to the local repository

cm = commit -m

Commit with a message
git cm "Updated some code stuff"  

aa = add -A

Stages all the changes in the workspace.

co = checkout

Checkout a branch or commit.
git co master  

Viewing History

lga = log --graph --oneline --all --decorate

Shows the history for the repository in a nice way.

lgab = log --graph --oneline --decorate

Shows the history for the current branch in a nice way.

Pushing & Pulling

plr = pull --rebase

pull but rebase instead of merge, find this useful when working on a branch that have others working in it to avoid merge commits. Makes the history much cleaner. See the internet for arguments about this.

pushup = "!git push --set-upstream origin \"$(git rev-parse --abbrev-ref HEAD)\""

Push a local branch to the origin remote, does what it says on the tin. Use this lots when working within a feature branch/pull request workflow.

Stash & Reset

Most of these I found on Phil Haacks blog

wip = !git add -A && git commit -m 'WIP'

Work in progress commit, commits anything to the current branch so it can be reverted later. Useful if you need to change what you are working on. You could use git stash but I prefer having a proper commit.

load = reset HEAD~1 --mixed

Used to undo the commit that was done with the wip command and put the changes in the working directory.

wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard

Really like this one, use it instead of "git reset --hard" to clear the current working directory. Much better because it still commits the changes before wiping so they will remain in your local repository until they are garbage collected.



No comments:

Post a Comment