Article directory
1、git clone
1-1. Definition
git clone is used to copy the remote warehouse to the local one. The entire version library is copied and a .git folder is generated in the folder directory, so there is no need to initialize it with the git init command;
1-2. Command
git clone <url> //url为要拷贝的远程库地址
There are two protocols for copying remote libraries:
Copying remote libraries through HTTPS protocol:
git clone https://github.com/buggetout/git_clone_test.git
Copy the remote repository via SSH protocol:
git clone git@github.com:buggetout/git_clone_test.git
2、git pull
2-1. Definition
The git pull command is used to get code from the remote end and merge it into the local version.
- git pull is the operation of git fetch and git merge
2-2. Command
git pull <远程仓库名> <远程分支名> : <本地分支名>
For example, the master branch of the origin branch of the remote warehouse is pulled over and merged with the local leaf01 branch:
git pull origin master : leaf01
If the remote branch is merged with the current local branch, the specified branch statement after the colon (including the colon) can be omitted, as follows:
git pull origin master
If the above pulls the specified branch origin/master from the remote warehouse and merges itMerge operation using command git petch
3、git fetch
3-1. Definition
The git fetch command is used to fetch the code base from the remote.
3-2. Command
git fetch <远程代码库名>//将指定远程库的更新全部取回本地
git fetch <远程代码库名> <远程分支名> //可以指定拉取远程哪个分支
-------
git merge <远程代码库名>/<远程分支名> //要是用git fetch拉取远程代码更新之后,git log FETCH_HEAD之后判断没有冲突后,用这个命令合并到本地分支上了
After using the command git fetch to pull the remote library code, aFETCH_HEAD, feedback the latest status of a certain branch on the server, and you can retrieve the updated status locally:
git log -p FETCH_HEAD
Determine whether there is a conflict based on the information and whether to merge into the current branch;
git merge <remote code base name>/<remote branch name>
4. The difference between git pull and git fetch
4-1. Differences in remote tracking
1. git pull:
git pull cannot directly operate on the remote tracking branch. You must first switch back to the local branch and then create a new commit submission;
2. git fetch:
git fetch can directly change the tracking branch;
4-2. Pull different
1. git pull: Get the latest version from the remote and automatically merge it locally, and it will be automatically merged and modified;
2. git fetch: Pull the data to the local warehouse, and it will not be automatically merged and modified;
4-3. Commit is different
1. git pull: Use git pull to update the code. The commit ID of the master in the local library will be changed to 2.
2. git fetch: Use git fetch to update the code. The commit ID of the master in the local library remains unchanged and is still equal to 1.