Skip to content

Instantly share code, notes, and snippets.

@tuannvm
Last active January 13, 2025 11:33
Show Gist options
  • Save tuannvm/b730885c76759514d614d298a8bc42b8 to your computer and use it in GitHub Desktop.
Save tuannvm/b730885c76759514d614d298a8bc42b8 to your computer and use it in GitHub Desktop.
#git #cheatsheet
git remote set-url origin git://new.url.here
  • unstage file
git reset HEAD <file>
git checkout -- <file>
  • check log
git log --oneline
  • check log and show graph
git log --online --decorate --graph --all
  • append a file to commit
git add <file>
git commit --amend --noe-dit # add file to latest commit without changing comment
git commit --amend # add file to latest commit AND change commit's comment
  • Rebase
git checkout <feature-branch>
git rebase master # append feature-branch with commit from master
  • fetch
git pull = git fetch + git merge
  • pull with rebase
# use when doing with small feature, hot fix
git pull --rebase <remote> <branch>
  • reflog

use git reflog to check and restore commit that has been reseted and can not recover by ordinary commit in git log

  • tag
  • lightweight: use on general case
git tag 1.0.0-beta
  • annotated: is a git object (commit), containing lots of info as ordinary commit
git tag -a 1.0.0 -m "mature release"
  • search
git tag -l "1.0*"
  • update ( switch commit)
git tag -a <tag-name> -f <commit>
  • delete
git tag <tag-name> --delete
  • push to remote
git push <remote> --tags
  • delete remote tag
git push <remote> :<tag-name>
  • push only annotated tags Hint: should push only annotated tags to github for clarification
git push <remote> --follow-tags
  • push annotated by default
git config --global push.followTags true
  • checkout tag
git branch -b <new-branch-name> <tag>
  • stash
git stash save "<message>" #  save stash with name
git stash -u #  stash both tracked and untracked file
git stash list #   list all stashes
git stash --keep-index #  don't stash staged file
git stash apply stash@{0} #  apply single stash
git stash apply --index #  apply and retain staged file
git stash drop stash@{0} #  drop single stash
git stash pop stash@{0} #  apply & drop at the same time
git stash clear # clear all
git stash branch <branch-name> #  migrate stash files to new branch
@tuannvm
Copy link
Author

tuannvm commented Jul 14, 2017

Clone with folder name:

git clone [email protected]:whatever folder-name

Add ticket number as prefix

@tuannvm
Copy link
Author

tuannvm commented Jul 31, 2017

git config --global alias.up '!git remote update -p; git merge --ff-only @{u}'

@tuannvm
Copy link
Author

tuannvm commented Sep 7, 2017

  • Create orphan branch:
git checkout --orphan orphan_name
  • push to gh-pages branch:

reference

git add dist && git commit -m "Initial dist subtree commit"
git subtree push --prefix dist origin gh-pages

@tuannvm
Copy link
Author

tuannvm commented Oct 1, 2017

quay.io tags-supported filter:

(heads/master)|(tags/(base-)?v([0-9]+)\.([0-9]+)\.([0-9]+))

@tuannvm
Copy link
Author

tuannvm commented Oct 17, 2017

Extra functionality here

@tuannvm
Copy link
Author

tuannvm commented Oct 24, 2017

Cherry pick here

@tuannvm
Copy link
Author

tuannvm commented Nov 12, 2017

  • Add file from other branch to current branch:
git diff --stat "$branch"
git checkout --merge "$branch" "$file"
git diff --stat "$branch"

@tuannvm
Copy link
Author

tuannvm commented Dec 8, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment