Git: Back up code to GitHub and copy code from GitHub to local

Source: Internet
Author: User

This article is written in the spirit of sharing, helping others, happy yourself, helping others, and serving the people in a brand new way. After reading this article, you will learn how to back up local code to GitHub in Linux and how to clone the code that interest GitHub to your local computer. In fact, there are a bunch of tutorials on git, but they are too scattered and mostly for experienced programmers. for students who have never used other version control tools, I did not speak carefully enough.

First of all, this article only provides a train of thought and operation steps, and does not involve specific operations, because I found that the official help documentation on GitHub is the most clear about how GitHub is used for backup on the Internet, I don't have to repeat here. Okay. Let's get started.

1. Go to the official website (https://github.com/) to register an account

2. Install git locally

sudo apt-get install gitsudo apt-get install git-doc git-svn git-email git-gui git-gitk

3. Git Configuration

git config --global user.name "yourname"git config --global user.email myaddress@gmail.com

4. Create a local repository

Assume that there is a folder in your home directory that stores the CD ~ /Code

Then you only need to run it in the Code directory.

git initgit add .git commit -m "first commit"

Git init initializes a local repository, the one above ". "indicates to add all the files and folder headers in the current directory to the local warehouse. It is submitted to the local warehouse only when 3rd sentences are executed.

5. It is important to back up data to GitHub, but it is a permanent task. For new users, how to authenticate the public key and private key is completely in the cloud, but there is little information about this step. For details about how to use SSH, refer to the official website:

Https://help.github.com/articles/generating-ssh-keys

6. After performing the preceding steps, you can back up the data to GitHub. Before backing up the data, we need to create a new repository (reso) on GitHub)

Https://help.github.com/articles/creating-a-new-repository

7. The following prompt appears after the repository is created:

Because we have already created a local repository, we can simply execute the following two statements under "push an existing repository from the command line.

In this way, the data is backed up to GitHub.

With the above work, we hope it is easy to clone a repository to a local location. Let's select a famous library to try it.

1. enter Facebook folly in the search box, select the first database, and click the fork button in the upper right corner, in this way, copy Facebook's open-source C ++ library folly to your own repository.

2. Go to your folly repository and find the following sentence:

3. You just need to execute the following sentence in your local directory.

 git clone git@github.com:lalor/folly.git

Do I have to make it clear? Well, there will be some related learning experiences in the future. Here we should remind you that the backup code is public, that is, what others can see and what privacy or photos are there, don't upload it. If you do not understand the information or make any mistakes in the article, please leave a message. Learn and make progress together.

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.