How to Use Git to upload project code to GitHub
This is my first time taking notes on applying Git. The following is for reference only by Git beginners.
GitHub is a Git-based code hosting 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, http://msysgit.github.com/,TortoiseGit:http://code.google.com/p/tortoisegit/ first before installation
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 compiling directories, which are not source code and ignored. suo files are vs2010 configuration files and are not required. In this way, you will only see the source code file during git status, so you can safely add-A to git.
GitHub Tutorials:
Create a personal technical blog via GitHub
GitHub tutorials
Git tag management details
Git branch management
Git remote repository details
Git local Repository (Repository) Details
Git server setup and Client installation
Git Overview
Share practical GitHub tutorials
GitHub details: click here
GitHub: click here
This article permanently updates the link address: