Skip to content

Instantly share code, notes, and snippets.

@uselessdev
Last active March 3, 2017 04:59
Show Gist options
  • Save uselessdev/c54d94c780c4b5a61c9c8a578188d744 to your computer and use it in GitHub Desktop.
Save uselessdev/c54d94c780c4b5a61c9c8a578188d744 to your computer and use it in GitHub Desktop.
Useful git bash functions

Git

Just paste this on your ~/.bash_profile, ~/.bashrc or ~/.zshrc, run source ~/.bashrc (or ~/.zshrc) and done!

nano ~/.bash_profile
# paste the functions below in your ~/.bash_profile and save it
source ~/.bashrc
# Git current branch
function git_current_branch {
  	(git branch | grep \* | cut -d ' ' -f2 )
}

# Git current username
function git_current_username {
	(git config -l | grep \user.name | cut -f2 -d"=")
}

# Git push
# $ push
function push {
  	(git push origin $(git_current_branch))
}

# Git pull
# $ pull
function pull {
	(git pull origin $(git_current_branch))
}

# Git clone
# $ clone <repository> <folder name> <username>
function clone {
	(git clone git@github.com:${3:-$(git_current_username)}/$1.git $2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment