Git learning-upload project code to GitHub

Source: Internet
Author: User
Tags git client

This is my first application of git. The following is only for reference by git beginners.
GitHub is a git-basedCodeHosting platform, paying users can build private warehouses. Generally, free users can only use public warehouses, that is, code should be made public. This is enough for ordinary people.

1. register an account and create a warehouse
To use GitHub, the first step is to register a GitHub account. Then you can create a warehouse (free users can only create a public warehouse), create a new repository, fill in the name, create, and some warehouse configuration information will appear, this is also a simple git tutorial.

2. Install the client tortoisegit
GitHub is a server. To use git on your computer, we still need a git client. tortoisegit is used here. It provides us with graphic interface operations. Install git before installation, http://msysgit.github.com/,tortoisegit:
Http://code.google.com/p/tortoisegit/
After the installation is complete, right-click and choose "Git init here" in the local repository to add a. Git folder, which indicates that the local git is successfully created. Right-click git bash and enter the GIT command line. to upload the local repository to GitHub, you also need to configure the SSH key.

3. Configure git
(1) Create an SSH key locally;
$ Ssh-keygen-t rsa-c "your_email@youremail.com"
After the your_email@youremail.com is changed to your mailbox, will ask to confirm the path and enter the password, we use the default one-way carriage return on the line. If it succeeds ~ /, Generate the. Ssh folder, go in, open id_rsa.pub, and copy the key. Go back to GitHub, go to account settings, select SSH keys on the left, add SSH key, enter the title, and paste the key.

 

(2) In git bash, enter:
$ Ssh-T git@github.com
If this is the first time, you will be prompted whether to continue. If you enter yes, you will see: You 've successfully authenticated, but GitHub does not provide shell access. This indicates that GitHub has been successfully connected.


 

 

 

 

 

(3) Next, we need to upload the local repository to GitHub. Before that, we need to set username and email, because every time GitHub commit records them.
$ Git config -- global user. Name "your name"
$ Git config -- global user. Name "Your name" $ git config -- global user. Email "your_email@youremail.com"
(4) enter the repository to be uploaded, right-click git bash, and add the remote address:
$ Git remote add origin git@github.com: yourname/yourrepo. Git
Yourname and yourrepo indicate your GitHub user name and the newly created repository. git: Open config. Here, there will be an additional remote "origin" content, which is the remote address just added. You can also directly modify config to configure the remote address.

 

4. Submit and upload
(1) Add some files in the local repository, such as README,
$ Git add readme
$ Git add readme $ git commit-M "first commit"
(2) Upload to GitHub:
$ Git push origin master
The GIT push command pushes the local repository to the remote server.
The GIT pull command is the opposite.
After the code is modified, you can use git status to view the differences between files. You can also use git add to add files to commit, or use git add-I to intelligently add files. After that, git commit submits this modification and git push uploads it to GitHub.
 
5. gitignore File
. Gitignore indicates the file to be ignored by git, which is a very important and practical file. Generally, after writing the code, we will perform compilation, debugging, and other operations. During this period, many intermediate files and executable files will be generated. These are not code files and do not need to be managed by git. We will see a lot of such files in git status. If you use git add-a to add them, it will be too troublesome to manually add them one by one. Then we need. gitignore. For example, in C # projects, my. gitignore is written as follows:

Bin
. Suo
OBJ

BIN and OBJ are compiled directories, neither of which isSource code, Ignore; the Suo file is the vs2010 configuration file, not required. In this way, you will only see the source code file during git status, so you can safely add-a to git.

 

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.