git config -l # list all the config of the repo git config --global -l # list all global config git config --global core.whitespace cr-at-eol # (Windows Git): Hide ^M (Carriage Return) in Diff git config --global core.autocrlf true# 提交时转换为LF(Linux \n),检出时转换为CRLF(Windows \r\n)
$ git checkout -b serverfix origin/serverfix Branch serverfix set up to track remote branch serverfix from origin. Switched to a new branch 'serverfix'
Create a new feature branch in remote.
1 2 3 4 5 6 7
# 1. Create a new branch: git checkout -b feature_branch_name
# 2. Edit, add and commit your files.
# 3. Push your branch to the remote repository: git push -u origin feature_branch_name
Undo the most recent commit
1
git reset HEAD~
Git submodule
If you want to git clone a repo alone with submodules. Use the following command:
If you have git clone a repo with submodule, you can find submodules’ folders, but the folders are empty.
1 2 3
git clone https://github.com/<repo-name>.git git submodule init # Init your local configuration file git submodule update # Will pull submodules you need
Use the above commands and you can have a complete repo.
Git clone
git clone a private repo
1 2 3 4 5 6 7 8 9 10 11 12 13
# Normal case git clone https://username:password@github.com/username/repository.git # or later input password git clone https://username@github.com/username/repository.git Password:
# [!!!] When using two-factor authentication(https://stackoverflow.com/a/52011442/8522166) # 2fa(https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/) $ git clone https://github.com/username/repo.git Username: your_username Password: your_token # or inline git clone https://username:token@github.com/username/repository.git
git pull will pull from origin/dev and merge to current dev branch. git pull origin master can pull origin/master and merge to current dev branch.[!!]
Example:
You are developing on local dev branch, push to the origin/dev at times for a pr. Now the master has some new updates and you would like to sync with master. You can use git pull origin master to pull master’s new update and merge to your branch.
1 2
$ git pull origin master Merge branch 'master' of github.com:arthma/iot-book into dev
Merge Two GitHub Repo
Say you have two github repo A and B. A is a copy of B and develop some features. Now you want to merge A back to B so the new feature can be added to B.
Go to B’s repo, git pull A’s code.
1 2
# In B repo. Pull A code git pull git@github.com:A-organization/A-project-name.git
Then solve conflicts, submmit commit, git push, done.