Skip to content

Instantly share code, notes, and snippets.

@iahim
Last active November 23, 2020 12:56
Show Gist options
  • Save iahim/019ab40b7088785a70d52a8d435c5637 to your computer and use it in GitHub Desktop.
Save iahim/019ab40b7088785a70d52a8d435c5637 to your computer and use it in GitHub Desktop.
GIT helpful commands
# Just a couple of commands i use on a daily basis.
# GIT IGNORE: https://www.atlassian.com/git/tutorials/saving-changes/gitignore
#========================================
# INITIAL SETUP
#========================================
git config --global user.email "xxx@gmail.com"
git config --global user.name "Mike Dev-VM"
# configure git to follow tags
git config --global push.followTags true
# push default current branch to remote origin
git config --global push.default current
# Most of the time you need to add/commit/push - for that I use the following linux bash alias:
#==================================================
# BASH UTILS
# ADD-COMMIT-PUSH ALIAS:
# USAGE: lazygit my commit text
#==================================================
__git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'
export PS1="\[$red\]\u\[$blue\]@\h\[$cyan\] \w \[$red\]$__git_branch\[$red\]#\[$none\] "
function lazygit() {
git add -A
git commit -a -m "$*"
git push
}
#========================================
# GIT PULL the latest changes
#========================================
# ignore any local changes and pull from remote
# this is useful when on a dev/uat/test server you need to pull the latest code
git reset --hard && git pull
#========================================
# GIT BRANCH
#========================================
# show local branches
git branch
# show all branches
git branch -a
# switch to another branch
git checkout <your_existing_branch>
# create a new branch (from current) and switch to it
git checkout -b <your_new_branch>
# delete a LOCAL branch
git branch -d hotfix
# delete a REMOTE branch
git push origin --delete <remote_branch>
#========================================
# GIT MERGE
#========================================
# if you want to get the code from branch dev into branch master:
git checkout master # switch to master branch
git merge dev # merge dev into master
#========================================
# GIT TAGS
#========================================
# CLONE A SPECIFIC TAG
# depth 1 means you don't want all the commit history, only current stuff
git clone --depth 1 --branch <tag_name> <repo_url>
# REMOVE A TAG locally and remote
git push --delete origin myTag
git tag -d myTag
# VIEW TAGS
git tag
# ADD A TAG (v1.2) - LOCALLY
git tag v1.2
# PUSH TAG to origin - REMOTE
git push origin v1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment