Verbatim large column https://www.dazhuanlan.com/2019/08/26/5d633a29ee4c5/
We usually remote from github and other library clones a new version of the code base, using
git clone username@xxx:/xxx/xxx.git
The default clone down is the master branch, no other branch
We can use git branch -a
to view all the branches, including local and remote
(If you only see the local branch, use the git branch
command to view only remote branches, use git branch -r
the command)
In team development, we often need to create multiple branches, each developed on a different branch, and then merge the code
The establishment of remote branch
If the team first created a branch manager for team members to use
That is created locally to the remote branch
You can directly create a local branch, assuming branch named dev
git branch dev
Then submitted to the local branch of a remote repository dev
git push origin dev
Next View remote branch
git branch -a
After the remote branch is created in the respective branch team members developed
Switch to the remote branch and merge other branches
First, before development, with git branch -a
view remote branch, then switch to the origin / dev remote branches, and a new branch in the local dev
git checkout -b dev origin/dev
At the same time established a link local and remote branch dev dev branch
Then the local branch dev developer, after development to push the remote branch (add commit these operations are omitted)
git push origin dev
For example, now you want to merge code branches of others, such as dev2, can
(Locally create a branch, then pulling dev2 code)
git checkout master
git branch dev2
git checkout dev2
git pull origin dev2
git add .
git commit -m "合并分支"
This operation is not recommended, because it is forced to push the line to a local branch dev2, and associated unfriendly
Or (pulling directly associated with a remote branch of local branch)
git checkout -b dev2 origin/dev2
Dev then switch back to the branch, if the branch line with changes dev2 combined branch line code dev2
git checkout dev2
git pull origin dev2
git checkout dev
git merge dev2
If you are updating dev code to dev2
git checkout dev
git pull origin dev
git checkout dev2
git merge dev
Create and update to the local branch line
git branch dev3
git push origin dev3
git fetch
If we pull the local branch line branched and do comparison, after confirmation merge code, may be used
git fetch origin master:tmp
git diff tmp
git merge tmp
The above code is to start on the master pulls up a local branch tmp, and then view tmp with the local branch of the existing branch changes, and then merge the branch tmp
Get the latest version is similar to git pull and merge from remote to local
git pull origin master
If you create a temporary branch line, you need to look at the case of remote branches
You can also use git fetch
all the update on a remote server dragged taken down
Then used locally git branch -a
to see all branches
Deleted branches
Delete the local branch
git branch -r dev3
Use uppercase D force delete, delete the branch in the presence of code changes uncommitted case
git branch -D dev3
Delete remote branch
git branch -r -d origin/dev3
git push origin :dev3
Not to submit commit switching branch
When we simultaneously develop two functional blocks, use two branches, you may need to switch at any time
And there are changes to the current branch, developed under the premise of not finished, do not want to submit code to operate commit, the switching branch will fail
If the development finished ready to commit, the changes will be submitted to the other branch, cause confusion
In this case, the best solution is to be executed on the current branch git stash
command, the current branch will save up
After the execution can be git status
verified that they are successful storage
Then you can create and switch to another new branch to develop a feature on the main branch master, after the functional development in the new branch is completed, we then switch back on a branch
With the git stash list
command to check out our list of "memory" of
Then use the git stash pop
command to restore a list of the most recently stored, while restoring the contents of the storage stash list is also deleted
Local rollback
It refers to already commit to a local warehouse store, but did not push to a remote
git reset --hard 22f8aae
22f8aae the version number commit, you can use git lig
to view
Remote Rollback
You can refer to the blog
bug fix
The use git pull Times refusing to merge unrelated histories, push Times Push rejected: Push to origin / master was rejected
Pull operation using the following commands
git pull [your remote repository address] [to pull the branch name] --allow-unrelated-histories
Such as
git pull [email protected]:lulujianglab/react-router-demo.git master --allow-unrelated-histories