Git code management: git remote add command [reproduced]

Author: Monet's old tricycle
Source: CSDN
link: https://blog.csdn.net/qq_25458977/article/details/87875641

 

Here is mainly how to submit a written code to two git remotes as an example to better understand the phrase git remote add;

First of all, we must understand the meaning of a sentence of code. Take the most frequent prompt of github as an example:

In this picture, git init, git add and git commit are all preliminary preparations, which are equivalent to uploading all your local files to the local warehouse, but they have not been submitted like a remote warehouse;

At this time, the phrase git remote is executed, which is to first establish a link between the local warehouse and the remote warehouse: git remote add, so what about add? The blue box is actually the name you gave to the remote warehouse, usually called origin, in fact, you can also ask for Ceres or Earth, and the green box is the real address of your remote warehouse;

For example, suppose I already have a folder in which my code is stored, and there is a file called README.md that has been written, then


 
  
  
  1. git init //Initialize a git local warehouse
  2. git add README.md //Load my files on the weapon and prepare to launch
  3. git commit -m "first commit" //First launch, my README.md baby has successfully entered the local warehouse
  4. git remote add Ceres your_first_git_address //Name the first git address Ceres
  5. git push -u Ceres master //Attention, I am going to launch to the far end of Jupiter. It's too far. I must use push. It's a hard drive
  6. //At this time, don’t move, and prepare to launch my README baby to Mars again.
  7. //But because my files already exist in the local warehouse, so I don’t need to commit and so on,
  8. //You only need to establish a connection between another remote warehouse and the local warehouse.
  9. git remote add Mars your_second_git_address //Name the second git address Mars
  10. git push -u Mars master //launch again, target the master branch on Mars

So far, I uploaded a copy of code to two remote warehouses, but note that you still only have one local warehouse.

supplement: 

When using git push -u Ceres master, also pay attention to where master is the name of the branch you want to upload. If the branch you are currently in is not called master, uploading with this sentence will make an error. For example:

Here my current branch is D***, but if I still use master, it will prompt an error:


 
  
  
  1. error: src refspec master does not match any.
  2. error: failed to push some refs to 'https://github.com/ns15417/RingDetectProject .git'

That is, the branch master to be pushed does not match the current branch,

$ git show-ref
 
  
  

Display the related branches of the remote;

It can be modified as follows;

$ git push --set-upstream personal_origin D**(当前分支名)
 
  
  

 

Guess you like

Origin blog.csdn.net/chenzz444/article/details/104403669