Upload code to GitHub with Git

   Step 1: We need to create a local repository (actually a folder).

       You can directly right-click to create a new folder, or you can right-click to open the Git bash command line window and create it with a command.

       Now I create a new TEST folder on the desktop through the command line (you can also create this folder anywhere else), and enter this folder

                                          

        

  Step 2: Turn this folder into a Git manageable repository by commanding git init

       

       At this time, you will find that there is a .git folder in TEST, which is used by Git to track and manage the repository. If you can't see it because it is hidden by default, then you need to set it to make hidden files visible.

       

  Step 3: At this point, you can paste your project into this local Git repository (you can view your current status through git status after pasting), and then add the project to the repository through git add (or git add . Add all files in this directory to the repository, note that the points are separated by spaces). You can actually always use git status to check your current status during this process.

       

       

       Here you are prompted that although the project has been pasted, it has not been added to the Git repository. Then we add all the copied projects to the repository through git add .

       

       

        Step 4: Submit the project to the repository with git commit.

        

        The quotation marks after -m are the comment content submitted this time. This can be omitted, but it is better to write it, otherwise an error will be reported, and the details will be Googled by yourself. Well, the work on our local Git repository is done, and now it's time to connect to the remote repository (that is, connect to Github)

      Since the transmission between the local Git repository and the Github repository is encrypted through SSH, you need to set the following when connecting:

      Step 5: Create SSH KEY. First check if there is a .ssh directory in the user directory of your C drive. If so, see if there are two files, id_rsa and id_rsa.pub. If so, skip to the next step. If not, create it with the following command

 

   $ ssh-keygen -t rsa -C "[email protected]"

       Then drive all the way back. Then you will find the two files id_rsa and id_rsa.pub in the .ssh directory under the user   

 

       

      Step 6: Log in to Github, find the icon in the upper right corner, open and click Settings, select SSH and GPG KEYS in it, click New SSH key in the upper right corner, then fill in the Title, and then put the id_rsa.pub just now. Copy the content to the Key content box under the Title, and finally click Add SSH key to complete the encryption of the SSH Key. The specific steps can also be seen below:

       

       

    

        Step 7: Create a Git repository on Github.

     You can directly click New repository to create it. For example, I created a TEST2 repository (because I already have a test repository in it, so I cannot create a TEST repository).

   

        Step 8: After creating the Git repository on Github, we can associate it with the local repository. According to the prompts on the created Git repository page, you can enter on the command line of the local TEST repository:

 

$ git remote add origin https://github.com/guyibang/TEST2.git

        

 

        Note that the address of the repository you created on Github is added after origin.

        

      Step 9: After the association is complete, we can push all the contents of the local library to the remote warehouse (that is, Github), through:

 

$ git push -u origin master

       Since the newly created remote repository is empty, you need to add the -u parameter. After the remote repository has content, the next time you upload content from the local repository, you only need to do the following:

 

 

$ git push origin master

 

        The process of uploading the project may take a while, and it looks like this after completion:

        

        At this time, if you refresh your Github page and enter the newly created repository, you will find that the project has been successfully uploaded:

      

        At this point, the entire process of uploading a local project to Github has been completed.

      In addition, there is a pit to pay attention to here, that is, when creating a remote repository in the seventh step above, if you checked Initialize this repository with a README (that is, a README file is automatically created for you when you create a repository), then it's time. In the ninth step, when you push the contents of the local repository to the remote repository, you will report a failed to push some refs to https://github.com/guyibang/TEST2.git error.

      

      This is because the README file in the newly created warehouse is not in the local warehouse directory. At this time, we can use the following command to merge the contents as follows:

 

$ git pull --rebase origin master

       

 

       Then you can push again and it will be successful.

 

     Summary: In fact, you only need to perform the following steps to upload your local project to Github

     1. Create a repository (ie folder) locally and turn it into a Git repository through git init;

     2. Copy the project to this folder, and then add the project to the warehouse through git add .

     3. Then submit the project to the warehouse through git commit -m "comment content";

     4. After setting the SSH key on Github, create a new remote warehouse and associate the local warehouse with the remote warehouse through git remote add origin https://github.com/guyibang/TEST2.git;

     5. Finally, push the project of the local warehouse to the remote warehouse (that is, Github) through git push -u origin master; (if the README file is automatically created when a new remote warehouse is created, an error will be reported, see the solution above).

Guess you like

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