Last active
April 28, 2021 05:56
-
-
Save phongvh/88677e8623cdf1fc7eb23f8731f9c306 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Git config | |
https://git-scm.com/docs/git-config | |
# Revert to previous checkout but keep history | |
git read-tree -u --reset <hash> | |
git commit | |
# Checkout a pull github request | |
git fetch $REMOTE pull/$PR_NUMBER/head:$BRANCHNAME | |
git checkout $BRANCHNAME | |
# Create a new ssh key | |
ssh-keygen -t rsa -b 4096 -C "phongvu@ohmnilabs.com" | |
# Add submodule | |
git submodule add git@github.com:phongvh/ddynamic_reconfigure.git src/ddynamic_reconfigure | |
# Clone with submodules | |
git clone --recurse-submodules -j8 git@github.com:phongvh/ros-ws.git # -j8 mean checkout 8 submodules simultaneously | |
# Update submodules | |
git pull --recurse-submodules | |
# Unstage an added file | |
git reset HEAD path/to/file # git reset -- path/to/file | |
git reset . # unstage all files | |
# Show branches | |
git branch -a | |
git branch -r (show remote branches) | |
# Checkout a commit into a branch | |
git checkout <commit> -b <branchname> | |
# or into current branch | |
git checkout <commit> . | |
# Merge two separate repositories | |
clone git@gitlab.com:kambria-wg/kambria-lego.git | |
cd kambria-lego | |
git log | |
git remote add skel git@gitlab.com:kambria-wg/kambria-skeleton.git | |
git fetch skel | |
git merge --allow-unrelated-histories skel/master | |
git status | |
git add all | |
git commit -m "Merge from Skeleton to Lego" | |
git remote remove skel | |
git push origin master | |
# Merge branch b4 to master | |
git checkout master | |
git merge b4 | |
# Abort merge | |
git merge --abort | |
# Merge favors <branch> (if there's a confict, use changes from <branch>) | |
git merge -s recursive -X theirs <branch> | |
# Create a branch from dev, make changes and merge to dev | |
$ git checkout -b myFeature dev | |
# make some changes | |
$ git commit -am "Your message" | |
$ git checkout dev | |
# why --no-ff? | |
$ git merge --no-ff myFeature | |
# To rollback to a specific commit: | |
# git reset --hard commit_sha | |
git reset --hard c3d47ec5af51f3d9b49afb934f55449dedce857b | |
# To rollback 10 commits back: | |
git reset --hard HEAD~10 | |
git push --force origin master | |
# REMOVE UNTRACKED FILES | |
git clean -n | |
git clean -f | |
# Revert changes in modified files. | |
git reset --hard | |
# Discard all unstaged changes | |
git checkout -- . | |
# Will discard all un-added changes even files in "unchanged" list. Be careful!! | |
git check -- . | |
git stash save --keep-index # git stash save "message" / --keep-index | |
git stash drop | |
# Stash changes | |
git stash save "stash 1" | |
git stash list | |
git stash pop | |
# Create tag | |
git tag -m "Version on Dec 17, 2014" v20141217 | |
git tag -n //list with annotation | |
# Delete tag | |
git tag -d 1.1.0 | |
git push origin :1.1.0 | |
# And if your tag has the same name as one of your branches, use this instead: | |
git tag -d [tag] | |
git push origin :refs/tags/[tag] | |
# Config to enable case insensitive (with file name) | |
git config (--global) core.ignore false | |
git mv Uppercase case | |
# Config to ignore file permission changes | |
git config --global core.fileMode false | |
# Enable color (git diff) | |
git config --global color.ui true | |
# Set default push = current branch instead of master branch | |
git config push.default current | |
git config pull.default current | |
git config -l | |
git config --global credential.helper osxkeychain (chua hoat dong) | |
# Show logs with information about changes | |
git log -p -m --first-parent | |
# delete remote branch | |
git push origin :delete_branch | |
# Override local changes (no need to stash but keep the new files) | |
git fetch --all | |
git reset --hard origin/master | |
# error: password for admin@phongvh.info => check if your public key is in /home/admin/.ssh/authorized_keys | |
# error-msys: middle-man or finger print: check ~/.ssh/known_hosts | |
# https://github.com/nvie/gitflow | |
# http://nvie.com/posts/a-successful-git-branching-model/ | |
# http://www.gitguys.com/topics/git-show-branch-to-see-branches-and-their-commits/ | |
# Show graph | |
gitk --all / gitk master | |
git log --graph --oneline --all | |
# Remove .git and compress the source | |
git archive --format zip --output /full/path/to/zipfile.zip master | |
# Untrack a file | |
git rm --cached mylogfile.log | |
# This will tell git you want to start ignoring the changes to the file | |
git update-index --assume-unchanged path/to/file | |
# When you want to start keeping track again | |
git update-index --no-assume-unchanged path/to/file | |
# List unchanged files | |
git ls-files -v | grep '^[[:lower:]]' | |
# List files | |
git ls-files -v | grep '^[a-z]' | |
git ls-files -v application/config | |
# Show ignored files | |
git ls-files --others --exclude-from=.git/info/exclude | |
# Remote | |
git remote show origin | |
git remote -v (show remote) | |
git remote add origin <git-url> | |
git remote set-url origin <git-url> | |
# ? | |
git checkout -b v1.0.1 v1.0 | |
git push --set-upstream origin v1.0.1 | |
# ? | |
git init | |
git remote add -t refspec remotename host:/dir.git | |
git fetch | |
git checkout refspec | |
git branch -D -r origin/dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment