Recently in the installation of Git ready to upload code to GitHub, because before the use of visual tools, many instructions are not clear, I thought it would not be too difficult, I did not get a long time did not fix. So I took the opportunity to sort out the process and then write it down.
1. Install git
Installing Git is always necessary to upload code to GitHub, or not to upload to GitHub, but only to version control locally. Direct Baidu git, or click here to go to the GIT official website, find the corresponding system version, download completed after selecting the installation location to complete the installation.
Once the installation is complete, right-click anywhere and see a git Bash here option to open the GIT command-line tool by selecting it.
Then you need to do some configuration and enter the following instructions:
" Your Name " "[email protected]"
Configure the global user name and mailbox with the name and mailbox you want to fill in the quotation marks.
The configuration information you set can be viewed through instructions.
git config--list
2. Create a GitHub remote repository
Version control through Git, if only the personal computer, you can directly refer to the GIT official website instructions, add, delete, modify and other operations, but often the development of many people through the git to manage, you need to upload the server to provide management and services, GitHub is the code Exchange platform for everyone using Git.
To use GitHub, you first need to register an account, complete the verification activation, just like a regular account registration, but this is in English. Using GitHub's remote repository, the local git and GitHub repositories are encrypted via SSH. Login to GitHub, click on Avatar Select settings can see SSH and GPG keys in the left menu bar, here is your github binding with local SSH public key information, if there are more than one computer, you can bind multiple keys. The GIT public key generation method is as follows:
Open git Bash on your computer and enter the following command:
Ssh-keygen " your email "
After the input has been selected to enter the right, the program will choose a default location to generate two files, according to the directory of the hint, locate the. ssh folder, the Id_rsa is the private key of the generated SSH key, to keep it yourself, another id_ Rsa.pub is a public key that tells others that we need to add the public key information to GitHub.
When you are finished, go back to the GitHub SSH interface, select the new SSH key in the upper right corner, and then the page prompts to fill in the title and key. Title fill in the name you want to use this PC, key need to just generate the public key, open id_rsa.pub, copy the text inside the key text box, click Add SSH Key, complete.
When you're done, build a repository on GitHub to save our code. Click the logo on the top left corner of the page to return to your home page, in the lower left corner of the page there is a repositories column, click New Repository to create a warehouse belonging to their own. According to the page prompt, fill in the name of the warehouse, description, select public (open warehouse owner visible, select private after not everyone visible, but need to charge), and then according to the needs of the choice is to initialize a project's initial document readme, click Create Repository created.
After creation, there is a paragraph just below the warehouse that prompts you to upload your local git code to GitHub, and in the settings of this repository, choose collaborators, search for the name of the small partner, and pull him in to develop together.
3. Add a project
Select the directory where the project has been created, or start creating a directory for the project, open git bash, or right-click the Git bash in the destination folder to enter:
Git init
This creates a Git project and generates a hidden. git file in the current location. At this point you can add the file you want to add to the buffer by using git add, or you can add a Readme MD file and then submit it via the git commit command, which you can then add to the description of the upload file via-M. Then you need to connect to our remote repository and complete the upload and update of the version. All instructions are as follows (for example, create readme.md directly from the code and add uploads for demonstration):
Echo " # Mybasicstudy " >>" Enter your instructions "-U Origin Master
All of the above Chinese should be replaced with their own reasonable content. The instructions from top to bottom are basically creating a readme.md file, initializing the current directory to a git managed directory, adding readme.md files like staging area, committing all staging area, adding a remote repository, the repository being the last URL to lose, and then updating the current version to GitHub.
It is important to note that when you use Git push to add files to a remote repository, you need to log in to your GitHub account, not the wrong user name (not the mailbox) and password (the error is re-push once on the line). When you're done, refresh the code page of the new GitHub remote repository, and you'll see that the instructions are gone, instead of just uploading the readme.md.
A more convenient tool
When we have a large project, adding files is a hassle, so you can use some tools to help us.
Sourcetree is a free git visual management software that can help us manage local code, remote repositories, and branches to avoid conflict issues as much as possible.
In addition, vs code is now officially supported by GIT, allowing easy staging and submission of managed code. And in the output of the VS code console you can see the specific execution of the GIT instructions.
On the left, the number 12 indicates the source code of GIT management, the + number is a staged change, the left is the undo change, the following managed files can be opened separately, undo changes, staged, and finally indicate the status of the file. Click on the + sign to click on the top of the OPT commit (equivalent to commit, submit to local. ), this time it will pop out an input box that asks for a description of the submission (that is, what was submitted).
Click Submit to the right of the ..., you can see a lot of features, and Sourcetree similar, synchronization, pull is to download the project from the remote repository, push is to pass the local code to the remote warehouse, here we direct point to push on it, because previously set the address of the remote warehouse, and the authentication of the account, So when you click Push, all of them take effect directly.
Later, as for more expansion of the function, you need to study ...
How to upload your local code to GitHub