Skip to main content


AndyBinOriginalAbout 1 min


View remote repository information

git remote

View remote repository details

git remote -v

Sync with remote repository code

git pull
# git pull = git fetch + git merge

Create a local branch corresponding to the remote branch

git checkout -b branch-name origin/branch-name
git switch -c branch-name origin/branch-name

Associate a local branch with a remote repository

git branch --set-upstream-to <branch-name> origin/<branch-name>

push local branch to remote repository

git push origin <branch-name>


The working mode of multi-person collaboration is usually as follows:

  1. First, you can try to push your own changes with git push origin <branch-name>;
  2. If the push fails, because the remote branch is newer than your local, you need to use git pull to try to merge first;
  3. If the merge has conflicts, resolve the conflicts and commit locally;
  4. If there is no conflict or the conflict is resolved, then push with git push origin <branch-name> and it will be successful!
  5. If git pull prompts no tracking information, it means that the link relationship between the local branch and the remote branch has not been created.

This is the working mode of multi-person collaboration, and once you are familiar with it, it is very simple.


  • If the new branch created locally is not pushed to the remote, it will not be visible to others;
  • Create a branch corresponding to the remote branch locally, and the names of the local and remote branches should be the same;
  • Fetch the branch from the remote, and if there is a conflict, resolve the conflict first.


The local repository has files and the remote repository also has files, but the two repository files are inconsistent. At this time, associate the local repository with the remote repository, execute git branch --set-upstream-to <branch-name> origin/<branch-name>, prompting an error: error: the requested upstream branch 'origin/ master' does not exist"

If you execute git pull directly, it will prompt: refusing to merge unrelated histories, the correct way:

git pull origin master --allow-unrelated-histories
git branch --set-upstream-to=origin/master master
git push origin master
Last update:
Contributors: rumosky
  • Latest
  • Oldest
  • Hottest