Skip to content

Instantly share code, notes, and snippets.

@mamuz
Last active May 28, 2017 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamuz/a161779f59c7eb978ac0945522624149 to your computer and use it in GitHub Desktop.
Save mamuz/a161779f59c7eb978ac0945522624149 to your computer and use it in GitHub Desktop.
Git Cheatsheet
https://github.com/github/hub
http://nuclearsquid.com/writings/git-tricks-tips-workflows/
# create repo from working dir
git init
git create `basename "$PWD"` -d "any descr" # use -p for private repo
git add --all && git commit -m "inital commit" && git push origin master
# update
git fetch # update target branches from remote excepts the current branch
git pull # update target branches from remote and merge it to your head (local branch): git fetch + git merge
# switch to another exiting remote branch
git fetch && git branch --all
git checkout {take name from branch list item, e.g for remotes/origin/dev use dev}
# create new branch
git checkout -b mybranch
## make some changes now
git push -u origin mybranch
# delete branch
git checkout master
git branch -D mybranch
git push origin :mybranch
# delete files
rm myfile
git commit -am 'deleted'
git push
## or
git rm myfile
git commit -m 'deleted'
git push
# file permissions: git only tracks executable permission
chmod +x myfile
git commit -am 'changed to exectubae'
git push
# overwrite local changes, excepts untracked files
git fetch --all
git reset --hard origin/master # or origin/branchname
# git change upstream
git branch --set-upstream branch_name your_new_remote/branch_name # origin/dev
# create tag
git fetch -t
git tag 0.0.2 # or with annotation: git tag -a 0.0.2 -m 'my tag name'
git push
# create release
git create -d -p release -m 'annotation' v0.1.0 # d = draft (means wip, optional); p: pre-release (means unstable, optional)
git fetch -t
# delete tag
git tag -d v0.1.0
git push origin :v0.1.0
# switch to tag with new branch
git checkout -b hotfix-v0.1.0 v0.1.0
git push origin hotfix-v0.1.0
# create pr
git pull-request # current branch into master; -i link to an issue
# accept pr, assuming you are in master and pr is from feature-any branch
git fetch origin
git checkout -b feature-any origin/feature-any
git merge master
## run all tests now
git rebase -i master
git checkout master
git merge feature-any
git commit --amend
git push origin
git branch -D feature-any && git push origin :feature-any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment