git remote -v
# origin https://github.com/NearHuscarl/dotfiles (fetch)
# origin https://github.com/NearHuscarl/dotfiles (push)
git remote set-url origin [email protected]:NearHuscarl/dotfiles.git
git remote -v
# origin [email protected]:NearHuscarl/dotfiles.git (fetch)
# origin [email protected]:NearHuscarl/dotfiles.git (push)
how to revert disastrous commit
git revert HEAD~2 # revert last 2 commit
Add 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 master
Delete tag
git tag -d <tag-name> # local
git push origin -d <tag-name> # remote
Push tag
git push --tags
Setup
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 cloning
git submodule update --init --recursive
git submodule update --recursive --remote
In submodule
git pull
In main repo
git commit -m 'update submodule'
git push
Create & move to new-branch
git checkout -b <new-branch>
Move to master
branch
git checkout master
Delete 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
--index
option 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/file
Vim 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:
]c
and[c
to move to next/previous hunk:diffget //2
to merge from target branch:diffget //3
to merge from merge branch:diffupdate
to 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 feature
then it'sfeature
) - Merge branch is the branch in the git merge argument (if you do
git merge master
fromfeature
branch, then it'smaster
)
References