First, remote warehouse
1.1 Adding a Remote Library
- git init
Initialize to a local repository
- git remote add origin url
Associate the local library with the remote library, the url is the address of the remote repository, and set a variable orgin to hold a local reference to the remote library
Git remote remove origin Unassociate a local repository with a remote repository
- git push -u origin master
Git will not only push the contents of the local master branch to the new remote master branch, but also associate the local master branch with the remote master branch. This will simplify the command in the future push or pull. (Origin stands for remote library)
- git push origin master
Then push the latest changes and you can simplify
But is there a good way to associate local repositories by adding remote repositories too cumbersome? Yes!!
1.2 Clone Warehouse
- git clone url
Git’s clone command will automatically name the remote repository Origin for you, pull all its data, create a pointer to its master branch, And locally name it Origin /master (origin/master can be thought of as a mirror of the master branch of the remote repository in the local repository). Git also gives you a local master branch that points to the same place as the Origin/Master branch
Q: If the remote repository has a bug in the dev branch as well as the master branch, will there be a bug in the dev branch after cloning the remote repository?
Answer: Yes!
Git branch = dev branch = master branch = dev branch = dev branch = master branch
Git Clone will fetch all branches of the remote repository. Git Clone will fetch all branches of the remote repository. The local branch will be named origin/master origin/dev origin/bug, and the result will be sent directly to the Repository. The local workspace will not automatically generate an editable copy.
Git branch can be found in the master branch, but not in the Dev bug branch.
Git will also give you a local master branch that points to the same place as the origin/master branch. Git will not automatically help you create a local dev branch that points to the same place as the Origin /dev branch, nor will the bug branch. Git will only automatically create a master branch that points to the same place as Master/Origin. Git branch can only see branches that exist in the workspace. Git branch -r: origin/master origin/dev origin/bug The content of the master branch is the same as the content of the master branch in the remote repository (because the master branch in the local repository points to the same place as the origin/master branch in the mirror).
Second, switch to the Dev branch for development
Create a new dev branch for the local repository and associate the dev branch of the local repository with the dev branch of the remote repository
- git checkout master
Switch to the master branch and create the dev branch on the master branch. This will not be messy if there are many branches, but you can also create dev branches on other branches
- git checkout -b dev
Create on the master branch and switch to dev branch
Git branch dev creates a branch
Git checkout dev Switches branches
- git branch –set-upstream-to=origin/dev dev
Then associate the remote repository dev branch with the local dev branch
Summary: The link between the local dev branch and the remote dev branch is based on fetching the origin/dev in the Repository from the clone Repository
But this is too cumbersome. Here is how to write a brief command
- git checkout -b dev origin/dev
Git dev = origin/dev = git /dev = git /dev = git /dev = git /dev = git /dev
Git branch now has a master branch and a dev branch. The local dev branch and the remote dev branch are identical (because the origin/dev branch and the local dev branch point to the same place).
!!!!!!!!! By the way, git fetch is also used to pull remote branches into the local repository. If the remote repository creates a new feature branch after cloning, what should be done?
Git fetch can be performed on any branch of the local repository, not on the master branch.
- git fetch
Git fetch (origin/feature) : git fetch (origin/feature) : git fetch
- git checkout -b feature origin/feature
Now the contents of the local feature branch and the remote repository feature branch are also consistent (because the local feature branch and the mirror origin/feature branch point to the same place). At the same time, the new feature created by Git in the local repository is based on the origin/feature in the version library in the local repository
Third, if the local warehouse needs to create a new plane branch, and develop a new function in the above, but the remote warehouse does not have this branch, what should be done?
- git checkout master
Switch to the main branch and create the dev branch on the main branch to keep the logic clear
- git checkout -b plane
Create and switch to the plane branch, which is only a local branch and has not been synchronized to the remote
- Git push Origin plane
Commit the branch plane to the remote repository. If the remote repository does not have the branch, a new branch will be created.
- git push –set-upstream origin plane
Then establish an association between the two branches. Note that the association is not branch. This is because there is no Git fetch, there is no origin/plane in the local version library, and the branch keyword cannot be associated. Git branch — -set-upstrem to=origin/plane
- git add .
After the development of the function, add temporary storage area
- Git commit -m
submit
- git push origin plane
Push to the Plane branch in the remote repository
Fourth, if you still have doubts about Git fetch, you can have a look at this blog. Personally, I think it is written very well, and I’d better have a look at it!
Git fetch understand
Git clone, push, pull, fetch
Git clone, push, pull, fetch
Six, the last is some common command list, we can take a look at this blog, the best look!
Common Commands