Reprinted from: GIT code management: git remote add
Here mainly to how the code will be submitted to an already written two git remote end, for example, to better understand the git remote add the phrase;
We must first understand the meaning of a code to github most often prompts an example:
In this drawing in git init, git add and git commit are preliminary preparation, the equivalent of your local files are uploaded to a local warehouse, but has not yet submitted images of the remote warehouse;
Then execute git remote that sentence, that is, first local and remote warehouse warehouse establish a link: git remote add, then add what is it? Your blue box is actually played for the remote repository name, usually called the origin, in fact, you may also want to Ceres or Earth, the green box is the real address of your distal end of the warehouse;
For chestnuts, I assume that there is already a folder, which kept their own code, which has a file called README.md already written, then
1 git git the init // initialize a local repository 2 3 git the Add README.md // my file loaded weapon, ready to launch 4 5 git the commit -m "First the commit" // first launch, my README .md baby has been successfully entered into the local repository 6 7 git the Add Remote Ceres your_first_git_address // the first git address named Ceres 8 9 git the Push -u Ceres Master // attention slightly, I would like to launch a distal Jupiter, too far away, be sure to use push, very strenuous catch the foot 10 11 12 // At this point, do not move, I was ready to re-launch the README baby to Mars, 13 14 // but because of my file already exists with the local warehouse , so I do not need to commit more room and so on, 15 16 // just to the distal end of another local warehouse and the warehouse will be able to establish a connection 17 18 git the Add Remote Mars your_second_git_address // named the second git address as Mars 19 20 git the Push -u Mars Master // re-emission, master branch on the target Mars
At this point, the code will be uploaded to a distal end of the two warehouses, but you still pay attention to only a local repository oh
supplement:
Note also that when using git push -u Ceres master master here is the name of the branch you want to upload, if you are currently located is not called the master branch, upload will be wrong with this sentence, for example:
Here is my current branch D ***, but I still used the master, you will be prompted an error:
1 error: src refspec master does not match any. 2 error: failed to push some refs to 'https://github.com/ns15417/RingDetectProject
It is to push the master branch does not match the current branch is located,
git show-ref
Display associated branch distal end;
Can be modified as follows;
git push --set-upstream personal_origin D ** (current branch name)