Git Study Notes <remote repository and tag Management> (4)

Source: Internet
Author: User

What is a remote repository?

As described in chapter 1, remote warehouses can store all source code and resource files you have written.

It can even be used as a network disk, but of course there are many features that fit the GIT management text.

The following describes how to use GitHub as an example remote repository. (You can also create a server as a remote repository by yourself ).

 

Create a repository

On the homepage, find + new repository or the plus sign in the upper right corner. Enter the name and description, and you can only make sure that you have no money to make public. Click the name to open your repository. (You can find it in the lower right corner of the home page)

 

Connection to remote warehouse

First, you have to prove your identity before opening your safe deposit box. Otherwise, how do I know that you are a customer who can store things?

So how to confirm the identity? Of course, the password is used, but this means that you need to enter the password every time, but through an SSH key.

Use

$ ssh-keygen -t rsa

 

Press enter directly. You do not need to set a password.

Such a command will ~ /. Create a private key and a public key in SSH (usually id_rsa and id_rsa.pub respectively. RSA is an encryption method, and there is also a DSA method ).

Just like you can make a key (Private Key) and a lock (Public Key) by yourself ). Hold the lock on your box and use your private key to open it.

Different from the reality, you can hold a lot of locks and put them in one hand ~ Besides, there are restrictions on putting things, not getting things. If you want to get things with restrictions, please pay for VIP ~

 

Register a user on GitHub. Click account settings in the upper-right corner. Click SSH keys. Click Add SSH keys. You can understand the title. Then open you ~ /. Id_rsa.pub under SSH (use gedit ~ /. Ssh/id_rsa.pub. You can also use Cat)

Copy the content. In this way, your box will be hung with your own lock. If you want someone else to put things in your box, you can send the lock (Public Key) to you.

 

Now you can push your local version library to a remote repository. Open the specified repository. There isSSHIf the clone URL is https, you can clone with HTTPS, ssh, or subversion. Click that SSH button to change to the SSH path. This address allows you to download or upload your version library by typing a command line. (There is also a download zip below. You can package and download other open source projects ).

Now go to your local repository. Input

$git remote add origin [email protected]:csdbianhua/learningGithub.git

In this way, the local database is associated with the remote repository. Orgin is the name you give to the remote database, and the following address should be copied.SSHClone URL.

It's okay to associate with others, but if you push it, you won't be able to lock it here.

Then, push your version library.

$ git push -u origin master

With the-u parameter added, git not only pushes the content of the local master Branch to a remote new master branch, but also associates the local master branch with the remote master branch.

If you submit the application later, you don't need to add U (this is the first time you push this branch ).

 

The following describes how to clone a remote database.

$ git clone [email protected]:csdbianhua/learningGithub.git

This command will create a learninggithub folder in the current directory, which contains the files in the library.

In addition, you can use other forms of links, and the speed of using HTTPS links is slow.

 

Multi-person cooperation

$ Git remote-V displays detailed (with-v) Remote repository information, including the addresses for capturing and pushing information. If you have no permission, you cannot see the push address.

Now, your friends can clone remote libraries to your local computer.

 

If yes, you can use

$git pull

To merge the remote database with the local database.

 

By default, clone only has the master branch.

To create other branches, use this command to create and clone Dev locally.

$ git checkout -b dev origin/dev

And

$ git push origin dev

To push the dev branch.

What if there is a conflict with the push?You can only get pull back to the local device and then manually resolve the conflict. It is the same as the conflict handling of branch merge in the previous chapter.

 

Sometimes $ git pull may fail. At this time, you can see that if this is the caseThere is no tracking information for the current branch.

That is, you have not bound a local branch to a remote warehouse. Use

$ git branch --set-upstream dev origin/dev

To bind a branch.

Okay, pull is back. The conflict is solved. Add is then commit-M "some message" and git pushes origin Dev.

 

If you want to push other open-source projects that do not have the permission to you, You can initiate a pull request. The project administrator can agree or disagree.

 

What is a tag?

A tag is a tag that you assign to the commit of a branch at a given moment.

 

Manage tags

For example, you can switch to the master branch. Type

$git tag v1.1

In this way, a label V1.1 is assigned to the last commit of the master.

$ git tag

 View All tagsIn alphabetical order.

ThinkTag a commitUse

$ git log --pretty=oneline --abbrev-commit

The commit list can be listed in one row. The following is my situation

54a09c4 just test
90c7aee commit Test
B26199e add licence.txt
7ce407c wrote a ReadMe file

In this case, you want to add licence.txt a label.

Type

$ git tag v1.0 b26199e

You can.View the commit information of the tag., Input

$ Git show V1.0
Commit b26199e24c11a9be640c26f5399eb3e240c77553
Author: Big Data <[email protected]>
Date: Tue Aug 5 15:35:32 2014 + 0800

Add licence.txt

Diff -- git a/license.txt B/license.txt
New File mode 100644
Index 0000000 .. bda4d91
---/Dev/null
++ B/license.txt
@-+ 1 @@
+ My name is Hanson
\ No newline at end of File
Diff -- git a/readme.txt B/readme.txt
Index d8036c1 .. 0740acc 100644
--- A/readme.txt
++ B/readme.txt
@-1, 2 + 1, 3 @@
-Git is a version control system.
-Git is free software.
\ No newline at end of File

Yes

$ git tag -a v1.0 -m "some text" b26199e

In this wayTag and write some remarks(-A specifies the label-M specifies the remarks)

$ git tag -s v1.0 -m "some text" b26199e

-Replace a with-s.Sign the label with the private key. You must install GPG. This signature cannot be forged.

 

Delete tagsUse

$ git tag -d v1.0

 

Push specific tags to a remote device

$ git push origin v1.0

Push all tags to remote

$ git push origin --tags

 Delete remote tagsWords

Delete the local file first.

$ git tag -d v0.9

Then delete the remote file in the following format.

$ git push origin :refs/tags/v0.9

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.