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. For ordinary people, public warehouses are enough, and we do not have much code to manage, O (pipeline _ pipeline) O ~. Below are some simple usage methods I have summarized for beginners.
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 msysgit
GitHub is a server. To use git on your computer, we still need a git client. Here I use msysgit, which only provides the core features of git and is based on command line. If you want a graphical interface, you only need to install tortoisegit on the basis of msysgit.
After installing msysgit, 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
First, create an SSH key locally;
$ ssh-keygen -t rsa -C "[email protected]"
Change [email protected] to your email address, and then you will be asked to confirm the path and enter the password. We will use the default one-way carriage return. 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. In git bash, enter:
$ ssh -T [email protected].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.
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.email "[email protected]"
Go to the repository to be uploaded, right-click git bash, and add the remote address:
$ git remote add origin [email protected].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
Next, add some files in the local repository, such as README,
$ git add README
$ git commit -m "first commit"
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.
6. Tag
We can create a tag to point to a critical period in software development. For example, when the version number is updated, we can create a tag such as "V2.0" and "v3.1, in this way, it will be more convenient for future review. Tag is easy to use. The main operations include viewing tags, creating tags, verifying tags, and sharing tags.
6.1 view tags
List all tags:
git tag
The tags listed in this way are sorted alphabetically and do not matter when the tag is created. If you only want to view some tags, you can add restrictions:
git tag -l v1.*
In this way, only version 1. is listed.
6.2 create a tag
Create a lightweight Tag:
git tag v1.0
The created tag does not contain any other information, and corresponds to the tag with information:
git tag -a v1.0 -m ‘first version‘
-M is followed by the annotation information, which will be useful for future viewing. This is a common tag, and there is a signature tag:
git tag -s v1.0 -m ‘first version‘
The premise is that you have a private key for GPG, just replace a with S. In addition to adding tags for the current progress, we can also add tags for the previous commit:
# First view the previous commit
git log --oneline
# Assume there is a commit: 8a5cbc2 updated readme
# Add tags for him
git tag -a v1.1 8a5cbc2
6.3 Delete tags
Very easy. After knowing the Tag Name:
git tag -d v1.0
6.4 verify tag
If you have a GPG private key, you can verify the tag:
git tag -v v1.0
6.5 shared tag
When we execute git push, the tag will not be uploaded to the server. For example, after the tag is created on GitHub, the tag cannot be seen on the GitHub webpage, to share these tags, you must:
git push origin --tags
Address: http://wuyuans.com/2012/05/github-simple-tutorial/