Git usage-How to upload a local project to GitHub

Source: Internet
Author: User

The first step: we need to first create a local repository (in fact, a folder).

You can right-click to create a new folder, or you can open a git bash command-line window by right-clicking the command.

Now I'll create a new test folder on my desktop from the command line (you can also make this folder anywhere else) and go to this folder

Step Two: Turn this folder into a git manageable repository by ordering git init

At this point you will find that there is a. git folder in test, which is used by Git to track and manage your repository. If you don't see it, because it's hidden by default, you need to set it up so that the hidden file is visible.

Step three: This time you can paste your project into this local git repository (after pasting you can view your current status through Git status) and then add the project to the repository (or git add) via git Add. Add all the files in this directory to the repository, Note that the points are separated by a space). In this process you can actually always use git status to see your current status.

Here you are prompted to paste the item, but not add it to the Git repository, and then we'll add it through git. All the items you just copied are added to the warehouse.

Fourth step: Commit the project to the repository with Git commit.

-M behind the quotation mark is the submission of the comment content, this can not be written, but it is best to write, or will error, the details of Google itself. Okay, we're done with our local git repository, and here's the connection to the remote repository (that is, GitHub).

Because the transfer between the local git repository and the GitHub repository is encrypted via SSH, the connection needs to be set up:

Fifth step: Create SSH KEY. Take a look at your C-drive user directory there is no. ssh directory, some words to see if there is no Id_rsa and id_rsa.pub these two files, have jumped to the next step, did not create by the following command

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

Then return all the way. At this point you will find the Id_rsa and id_rsa.pub two files in the. SSH directory under the user.

Sixth step: Login to GitHub, find the upper right corner of the icon, open the point into the inside of the settings, and then select the inside of the SSH and GPG keys, click on the upper right corner of the new SSH key, and then the title filled, then put just id_ Rsa.pub inside the content copied to the title under the Key Content box, and finally click on the Add SSH key, so that the completion of the SSH key encryption. Specific steps can also be seen below:

Seventh step: Create a git repository on GitHub.

You can create a new repository directly, for example, I created a TEST2 repository (because I already have a test repository in it, so I can't create a test repository anymore).

Eighth step: After creating a git repository on GitHub, we can associate with the local repository, which can be entered at the command line of the local test repository, depending on the prompt to create a good git repository page:

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

Note that origin is appended with the address of the warehouse you created on GitHub.

Nineth step: After the connection, we can push all the contents of the local library to the remote Repository (GitHub), by:

$ git push -u origin master

Because the new remote warehouse is empty, so to add-u this parameter, and so on the remote repository inside the content, the next time from the local library upload content only then can be:

$ git push origin master

The process of uploading a project may take a while to complete:

This time you re-refresh your github page into the newly created warehouse and you will find that the project has been successfully uploaded:

This completes the entire process of uploading the local project to GitHub.

In addition, there is a pit to note, is in the seventh step above the creation of the remote repository, if you check the Initialize this repository with a readme (that is, when the warehouse is created automatically to create a Readme file), So in the Nineth step, when you push the local repository content to the remote repository, you report a failed to push some refs to https://github.com/guyibang/TEST2.git error.

This is because the Readme file in your newly created warehouse is not in the local repository directory, so we can merge the following commands first:

$ git pull --rebase origin master

Then you can push and you will succeed.

Summary: In fact, only the following steps will be able to upload local projects to GitHub

1. Create a repository (i.e. a folder) locally and turn it into a git repository via git init;

2. Copy the project into this folder and add it through git. Adding items to the warehouse;

3, then through the git commit-m "comment content" to submit the project to the warehouse;

4. After setting the SSH key on GitHub, create a new remote repository to associate the local repository with the remote repository via git remote add Origin https://github.com/guyibang/TEST2.git;

5, finally through the GIT push-u origin master to push the local warehouse project to the remote repository (that is, GitHub), (if the new remote repository automatically created a Readme file will be error, the solution to see above).

Git usage-How to upload a local project to GitHub

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.