How to use github? github simple use tutorial (transfer)

    github (https://github.com) is a git-based code hosting platform. Paid users can build private repositories. Our general free users can only use public repositories, that is, the code must be made public. For the average person, the public repository is enough, and we don't have much code to manage, O(∩_∩)O~. The following are some simple usage methods I have summarized for beginners' reference.

1. Registering an account and creating a

warehouse The first step in using github is, of course, to register a github account. After that, you can create a repository (free users can only build public repositories), Create a New Repository, fill in the name and Create, and then some configuration information of the repository will appear. This is also a simple tutorial for git.

2. Install the client msysgit

github is the server. To use git on our own computer, we also need a git client. I choose msysgit here, which only provides the core functions of git and is based on the command line. If you want a graphical interface, just install TortoiseGit on top of msysgit.

After installing msysgit, the right mouse button will have some more options. Right-click on the local repository and select Git Init Here. There will be an additional .git folder, which means that the local git is successfully created. Right-click Git Bash to enter the git command line. In order to transfer the local repository to github, you also need to configure the ssh key.

3. Configure Git

to 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 just use the default all the way to enter. If successful, the .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, and paste the key. To verify success, enter under git bash:

$
ssh
-T [email protected]


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 need to do is to upload the local repository to github. Before that, we need to set username and email, because github will record them every time we commit.

$ git config --global user.name
"your name"


$ git config --global user.email
"[email protected]"


Enter the repository to be uploaded, right-click git bash, and add the remote address:

$ git remote add origin [email protected]:yourName/yourRepo.git


The following yourName and yourRepo indicate your github username and the newly created warehouse. After adding, enter .git and open config. There will be an extra remote "origin" content, which is the remote address you just added. You can also modify it directly. 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 does the opposite.

After modifying the code, you can use git status to view the differences between files, use git add to add files to be committed, or use git add -i to add files intelligently. After that, git commit submits this modification, and git push uploads it to github.

5. gitignore file. gitignore

, as the name suggests, is a file that tells git to ignore, which is a very important and practical file. Generally, after we write 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 a lot of such files in git status. If we use git add -A to add them, we will add them all, and it is too troublesome to add them one by one manually. At this point we need .gitignore. For example, in a general c# project, my .gitignore is written like this:

bin


*.his


obj
bin and obj are the compilation directories, which are not source code, so ignore them; the suo file is the configuration file of vs2010, which is not required. In this way, you will only see the source code files when you are in git status, and you can git add -A with confidence.

6.tag

We can create a tag to point to a key period in software development. For example, when the version number is updated, a tag such as "v2.0" and "v3.1" can be created, so that it will be reviewed later. More convenient. The use of tags is very simple. The main operations are: viewing tags, creating tags, verifying tags, and sharing tags.

6.1 View tags
List all tags:

git day


The tags listed in this way are in alphabetical order, regardless of creation time. If you just want to view certain tags, you can add restrictions:

git tag -l v1.*


This will only list the 1.1 version.

6.2 Create tags
Create lightweight tags:

git tag v1.0


The tag created in this way has no other information attached, and the corresponding tag is the tag with information:

git tag -a v1.0 -m
'first version'


-m is followed by comment information, which will be useful for viewing in the future. This is a normal tag, and there is a signed tag:

git tag -s v1.0 -m
'first version'


The premise is that you have the GPG private key, just replace the above a with s. In addition to adding tags to the current progress, we can also add tags to previous commits:

#First look at previous commits

git log --oneline

#If there is such a commit: 8a5cbc2 updated readme


#Add tag for him like this


git tag -a v1.1 8a5cbc2


6.3 Deleting a tag
is very simple. After knowing the tag name:

git tag -d v1.0


6.4 Verify tag
If you have the GPG private key, you can verify the tag:

git tag -v

v1.0


6.5 Sharing tags
When we execute git push, the tags will not be uploaded to the server. For example, in the current github, after creating tags, git push will not see the tags on the github webpage. In order to share these tags, you must do this :

git push origin --tags

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326990482&siteId=291194637