git remote -v
# origin https://github.com/NearHuscarl/dotfiles (fetch)
# origin https://github.com/NearHuscarl/dotfiles (push)
git remote set-url origin git@github.com:NearHuscarl/dotfiles.git
git remote -v
# origin git@github.com:NearHuscarl/dotfiles.git (fetch)
# origin git@github.com:NearHuscarl/dotfiles.git (push)how to revert disastrous commit
git revert HEAD~2 # revert last 2 commitAdd tag
git tag -a <tag-name> -m <long-description>Add tag point to an old commit
# Set the HEAD to the old commit that we want to tag
git checkout 9fceb02
# temporarily set the date to the date of the HEAD commit, and add the tag
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" \
git tag -a v1.2 -m"v1.2"
# set HEAD back to whatever you want it to be
git checkout masterDelete tag
git tag -d <tag-name> # local
git push origin -d <tag-name> # remotePush tag
git push --tagsSetup
git config --global core.hooksPath ".hooks"In /path/to/repo/.hooks/ Create hook file. Example name for hook: .hooks/pre-commit, .hooks/commit-msg
git submodule add <url> <name>
# e.g. git submodule add https://github.com/NearHuscarl/dictionary-data.git Data
git commit -m 'add submodule' # commit immediately after cloninggit submodule update --init --recursivegit submodule update --recursive --remoteIn submodule
git pullIn main repo
git commit -m 'update submodule'
git pushCreate & move to new-branch
git checkout -b <new-branch>Move to master branch
git checkout masterDelete branch
git branch -d <branch-name>git stash
git pull
git stash apply --index- Store your changes tempoparily in the stash and remove them from current working directory
- Pull change from other party
- Restore changes from the stash. (the
--indexoption is useful to make sure that staged files are still staged)
If auto merge failed. Use vim to resolve merge conflicts
vim path/to/conflict/fileVim will open 3 buffers:
- the left one is target branch
- the midde one is current working copy
- the right one is merge branch
Some useful commands when merging in vim:
]cand[cto move to next/previous hunk:diffget //2to merge from target branch:diffget //3to merge from merge branch:diffupdateto update out-of-sync diff
After solving merge conflict. Close all the buffer except the middle one (working copy) by typing
:only in the middle buffer
Note:
- Target branch is the current active branch (if you do
git checkout featurethen it'sfeature) - Merge branch is the branch in the git merge argument (if you do
git merge masterfromfeaturebranch, then it'smaster)
References