Use Git for the first time to upload a local project to GitHub

Source: Internet
Author: User

For the program has heard that Github,github has a lot of open-source projects and some cutting-edge technology. Because I have just started to use git to write some of their own small dome on GitHub encountered many pits, so long gone, want to use Git upload code for the first time to do a summary, so as not to forget.

1. Download git software: https://git-scm.com/downloads, it is said that iOS comes with Git software, this I am not very clear.

2. After downloading the installation is very simple, the next step on the way to it. After the installation is complete, the mouse right click and Start program will appear, open git bash, into the bash interface.

Next is the focus, if this step is not passed, the secret key does not have the certification completed, you can not upload files, this has stepped on the pit, has been English tips tell the Who is you;

3. Email Registration

Enter the following in the GIT bash interface to complete the mailbox registration:

$ git config--global user.name "User.Name"

(Note: You need your user name in double quotes, this can be entered casually, such as "Zhangsan")

$ git config--global user.email "[Email protected]"

(Note: You need to enter your valid mailbox in double quotes, such as "[email protected]")

4. See if there is a key SSH keys

If "No such file or directory" appears, you need to create an SSH keys.

My keys have been set, as in the following states:

5. If not set, create a new SSH keys, or git cannot upload files

$ssh-keygen-t rsa-c "Your mailbox name"

$ specified directory: C:\deskbook\ (Note: If the path is not entered here, and directly press ENTER, then SSH keys will be stored after the path is C:\USER\.SSH)

$ Enter Password: 123456

$ Confirm Password: 123456

This allows you to generate SSH keys in the C:\deskbook\ folder. including two files Rd_rsa and id_rsa.pub

Then find the directory where Rd_rsa and id_rsa.pub are open idb_rsa.pub (you can change the suffix to. txt), log into your GitHub account, find settings,

After entering settings, click SSH and GPG keys, then click on the upper right corner to add the Xinmi key button new SSH key,

Then, copy the contents of the idb_rsa.pub into the key, the title content can be filled in, OK.

The key is added and the next time you use it, you won't need to add the key again.

6. Start uploading local files to git.

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'm creating a new TestApp folder on my desktop from the command line (you can also create this folder anywhere else) and go to this folder

A folder will appear on your desktop and you can copy your project code in

7. Command git init to turn this folder into a repository that git can manage

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.

8. You can then paste your project into this local git repository (after pasting you can view your current status through Git status) and add the project to the repository (or git add) via git add . Add all the files in the directory to the warehouse, and note that the points are separated by a space. In this process you can actually always use git status to see your current status. If there is something in the file that will appear red, not green, this is not an error.

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.

9. use git commit-m "log" to submit the project to the repository.

Create a git repository on GitHub.

You can create a new repository directly, for example, I created a xiaobing warehouse. Enter the Warehouse

One by one. 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 TestApp repository, depending on the prompt to create a good git repository page:

Note that origin is appended to the address of the warehouse you have created on GitHub, which is the second click on the copied address.

Once connected, we can push all the contents of the local repository 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're going to report a to https://github.com/sdc123456789/xiaobin 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

Note: If the pop-up box allows you to fill in your username and password, simply fill in the GitHub account number and password.

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).

The above is just my first use of the summary, there is time later I will put Git tool turtle use to summarize.

Use Git for the first time to upload a local project to GitHub

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.