Git review

  I did an OS experiment two days ago, and I was fascinated by a wave of Git operations. I think I didn’t understand it carefully enough. Summarize the knowledge about remote operation of Git push and Git pull.

git push

1. git push uses the corresponding local branch to update the corresponding remote branch.  

1 git push <remote host name> <local branch name>:<remote branch name> ,

 Note: The local branch name refers to the branch to be pushed to the remote, while the remote branch refers to one of the target branches of the remote host where the push is made.

Second, the difference

a.   git  push origin master

b.   git push origin :master    

c. git push origin

d. git push

e. git push -u origin master

f. git push --all origin

g. git push --force origin

  1. Omit the remote branch name

  If the remote branch name is omitted, it means that the local branch will be pushed to the remote branch with which there is a "tracking relationship" (usually the two have the same name). If the remote branch does not exist, it will be created.

  In a, the colon and the following remote branch name are omitted. This sentence means: push the local master branch to the master branch on the origin host, and if the latter does not exist, create a new remote master of the master branch.

  2. Omit the local branch name

  If the local branch name is omitted, it means to delete the specified remote branch, as this is equivalent to pushing an empty local branch to the remote branch.

  The command in b is to delete the remote master branch. It is equivalent to git push origin --delete master

  3. Omit local branch and remote branch names

  If there is a tracking relationship between the current branch and the remote branch, then both can be without any parameters.

  4. Omit the hostname

   If the current branch has only one tracking branch, the hostname can be omitted.

   5. Use the default hostname

  If the current branch has a tracking relationship with multiple hosts, you can use -u to specify a default host, so that you can use git push directly later.

  6. Push all local branches to the origin host

  All local branches can be pushed with the --all option.

  7. Force push

  If the version of the remote host is newer than the local version, Git will report an error when pushing, and it is required to do Git pull locally to merge the differences, and then push to the remote host. At this time, if you want to force push, you can use -force. (Forcing a push will cause the host to generate a non-fast-forward merge, which is not recommended in uncertain circumstances.)

git pull

  git pull fetches and merges other factory repositories, or other local branches.  

git pull <remote host> <remote branch>:<local branch>

 

 

 

  E.g:

  git pull origin master:lab2

It means to pull the master branch on the origin host to the local lab2 branch.

Others are similar.

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325105734&siteId=291194637
Git