Github is a code hosting platform based on git. Paying users can build private warehouses. Our general free users can only use public warehouses, which means the code must be made public. For ordinary people, a public warehouse is enough, and we don't have much code to manage it, O(∩_∩)O~. Steps:
1. Register an account and create a warehouse
The first step if you want to use github is to register a github account. After that, you can create a warehouse (free users can only build public warehouses), Create a New Repository, fill in the name and create, and then some warehouse configuration information will appear. This is also a simple tutorial on git.
2. Install the client msysgit
Github is the server. If you want to use git on your own computer, we also need a git client. I choose msysgit here. This is just provided. The core functionality of git is based on the command line. If you want a graphical interface, just install TortoiseGit based on msysgit.
After installing msysgit, right-click the mouse and some more options will appear. Right-click in the local warehouse and select Git Init Here. An additional .git folder will appear, which means that the local git is created successfully. Right-click Git Bash to enter the git command line. In order to transfer the local warehouse to github, you also need to configure the ssh key.
3. Configure Git
First create the ssh key locally;
$
ssh-keygen
-t rsa -C
"your_email@youremail.com"
Change the following your_email@youremail.com to your email address, and then you will be asked to confirm the path and enter the password. Here we Just use the default all the way and press Enter. If successful, a .ssh folder will be generated under ~/, go in, open id_rsa.pub, and copy the key inside.
Go back to github, enter Account Settings, select SSH Keys on the left, Add SSH Key, fill in the title as you like, and paste the key. In order to verify whether it is successful, enter under git bash:
$
ssh
-T git@github.com
If it is The first time you will be prompted whether to continue, enter yes and you will see: You've successfully authenticated, but GitHub does not provide shell access. This means that you have successfully connected to github.
The next thing we have to do is to upload the local warehouse to github. Before that, we need to set the username and email, because github will record them every time they commit.
$ git config --global user.name
"your name"
$ git config --global user.email
"your_email@youremail.com"
Enter the warehouse to be uploaded, right-click git bash, and add the remote address:
$ git remote add origin git@github.com:yourName/yourRepo. git
The yourName and yourRepo behind it represent your github user name and the newly created warehouse. After adding it, enter .git and open config. There will be an extra remote "origin" content here, which is what you just added. The remote address can also be modified directly by modifying the config to configure the remote address.
4. Submit and upload
Next add some files in the local warehouse, such as README,
$ git add README
$ git commit -m
"first commit"
Upload to github:
$ git push origin master
The git push command will Push the local repository to the remote server.
The git pull command is the opposite.
After modifying the code, use git status to view the differences in the files, use git add to add files to be committed, or use git add -i to intelligently add files. Then git commit submits this modification, and git push uploads it to github.
5.gitignore file
.gitignore, as its name implies, tells git which files need to be ignored. This is a very important and practical file. Generally, after we finish writing the code, we will perform operations such as compilation and debugging. 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 many such files in git status. If we use git add -A to add them, they will be added. However, it is too troublesome to add them one by one manually. At this time we need .gitignore. For example, for general C# projects, my .gitignore is written like this:
bin
*.suo
obj
bin and obj It is the compilation directory, and it is not the source code, so ignore it; the suo file is the configuration file of vs2010 and is not needed. In this way, you will only see the source code files in git status, and you can safely git add -A.
6.tag
We can create a tag to point to a key period in software development. For example, when the version number is updated, we can create a "v2.0", "v3. 1" and so on, which will be more convenient when reviewing in the future. The use of tag is very simple. The main operations are: view tag, create tag, verify tag and share tag.
6.1 View tag
List all tags:
git tag
The tags listed in this way are sorted alphabetically, and It doesn't matter when it was created. If you only want to view certain tags, you can add restrictions:
git tag -l v1.*
This will only list versions 1.
6.2 Create tag
Create lightweight tag:
git tag v1.0
The tag created in this way does not come with other information , corresponding to the tag with information:
git tag -a v1.0 -m
'first version'
-m It is annotation information, which will be very useful when viewing it in the future. This is an ordinary tag, and there is also a signed tag:
git tag -s v1.0 -m
'first version'
The premise is that you have a GPG private key, just replace the a above with s.
In addition to adding tags to the current progress, we can also add tags to previous commits:
#First view the previous commits
git log --oneline
#If there is such a commit: 8a5cbc2 updated readme
#Add a tag for it like this
git tag -a v1.1 8a5cbc2
6.3 Delete tag< /p>
It’s very simple, after knowing the tag name:
git tag -d v1.0
6.4 verification tag
If you have a GPG private You can verify the tag if you have the key:
git tag -v
v1.0
6.5*** Enjoy tag
We are When executing git push, the tag will not be uploaded to the server. For example, in the current github, after creating the tag and git push, the tag will not be visible on the github web page. In order to fully share these tags, you must do this: < /p>
git push origin --tags