Git - yenbohuang/techNotes GitHub Wiki
- Pro Git https://git-scm.com/book/en/v2
- Eclipse EGit https://wiki.eclipse.org/EGit/User_Guide
- Forking workflow https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow
- master
- The default name for a starting branch when you run git init.
- origin
- The default name for a remote when you run git clone.
- Tracking branch and upstream branch
- Checking out a local branch from a remote-tracking branch automatically creates what is called a "tracking branch".
- And, the branch it tracks is called an "upstream branch".
- Tracking branches are local branches that have a direct relationship to a remote branch.
Configurations are set in ~/.gitconfig
.
git config --global user.name "John Doe"
git config --global user.email [email protected]
Configure Git on OS X or Linux to properly handle line endings
git config --global core.autocrlf input
Configure Git on Windows to properly handle line endings
git config --global core.autocrlf true
https://help.github.com/en/articles/configuring-git-to-handle-line-endings
git config --list
git clone https://github.com/libgit2/libgit2
Show complete details:
git status
Show simple status:
git status -s
git add <file or directory>
git mv <old file name> <new file name>
git checkout -- <file>
Commit files (no need to use git add
) with message:
git commit -a -m <message>
Commit and open default editor:
git commit
Commit with message:
git commit -m <message>
Change commit message or add forgotten files:
git commit --amend
git rm <file or directory>
If you modified the file and added it to the index already, you must force the removal with the -f option:
git rm -f <file or directory>
Keep the file in your working tree but remove it from your staging area:
git rm --cached <file or directory>
git reset HEAD <file>
git reset --hard HEAD^
git remote -v
git remote show <remote name>
Add a new remote Git repository as a remote name:
git remote add <remote name> <url>
Add a remote for your local git that references upstream:
git remote add upstream <url>
git pull
git push <remote name> <branch name>
Push "master" branch to "origin" server:
git push origin master
git remote prune origin
Create a branch:
git branch <branch name>
Switch to a branch:
git checkout <branch name>
Create and switch to a branch
git checkout -b <branch name>
Push a branch to remote:
git push <remote name> <branch name>
Push a branch to where you pulled it:
git push origin <branch name>
git branch -vv
Merge branch back to master:
git checkout master
git merge <branch name>
Update master to branch:
git checkout <branch name>
git merge master
git branch -d <branch name>
- git cherry-pick says “…38c74d is a merge but no -m option was given”
- Git cherry-pick syntax and merge branches
git cherry-pick <commit SHA>
git cherry-pick -m <# of parent starting from 1> <commit SHA>
Point environment variable HOME
to another folder.
See details in https://superuser.com/questions/1183044/how-can-i-change-my-mingw-msys-mintty-home-directory.