Git remote usage

Source: Internet
Author: User
Tags comments commit ssh using git git clone
to participate in the collaboration of any Git project, you must know how to manage the remote repository. A remote repository is a project repository that is hosted on a network, and there may be several, some of which you can only read and others to write. When collaborating with others to develop a project, you need to manage these remote warehouses. To push or pull data and share the progress of their work. Manage remote repositories, including adding remote libraries, removing obsolete remote libraries, managing various remote library branches, defining whether to track these branches, and so on. This section discusses the management and use of remote libraries in detail.

 View the current remote library

To see which remote repositories are currently configured, you can use the GIT remote command, which lists a short name for each remote library. After you clone a project, at least one remote library named origin is visible, and git uses that name to identify the original repository you cloned by default:

$ git clone git://github.com/schacon/ticgit.git

Initialized Empty Git repository in/private/tmp/ticgit/.git/

Remote:counting objects:595, done.

Remote:compressing objects:100% (269/269), done.

Remote:total 595 (Delta 255), reused 589 (Delta 253)

Receiving objects:100% (595/595), 73.31 KiB | 1 kib/s, done.

Resolving deltas:100% (255/255), done.

$ CD Ticgit

(1) Git remote does not have parameters, list the existing branch

$ git remote

Origin

(2) git remote-v | --verbose lists the details, listing their remote URLs after each name

At this point, the-v option, which is shorthand for –verbose, takes the first letter, displays the corresponding clone address:

$ git remote-v

Origin Git://github.com/schacon/ticgit.git If you have more than one remote repository, this command will all be listed. For example, in my Grit project, you can see:

$ CD Grit

$ git remote-v

Bakkdoor Git://github.com/bakkdoor/grit.git

Cho45 Git://github.com/cho45/grit.git

Defunkt Git://github.com/defunkt/grit.git

Koke Git://github.com/koke/grit.git

Origin this way, I can easily pull their commits from these users ' warehouses to local. Please note that the address listed above only has the SSH URL link, so only this warehouse I can push the data up (we will explain the reason in the fourth chapter).

Add a remote repository

To add a new remote repository, you can specify a simple name for future reference, run git remote add [shortname] [url]:

$ git remote

Origin

$ git remote add PB git://github.com/paulboone/ticgit.git

$ git remote-v

Origin Git://github.com/schacon/ticgit.git

PB Git://github.com/paulboone/ticgit.git can now use a string of PB to refer to the corresponding warehouse address. For example, to crawl all of the information that Paul has but the local repository does not have, you can run git fetch PB:

$ git fetch PB

Remote:counting objects:58, done.

Remote:compressing objects:100% (41/41), done.

Remote:total (Delta), reused 1 (Delta 0)

Unpacking objects:100% (44/44), done.

From Git://github.com/paulboone/ticgit

* [New branch] master, Pb/master

* [New branch] Ticgit-Pb/ticgit

Now, Paul's Trunk branch (master) is fully accessible locally, and the corresponding name is Pb/master, you can merge it into one of your branches, or switch to this branch to see what's interesting and more


two. Build a remote repository from git remote

set up a remote repository

Recently have been learning to use git to manage their own programs, always learn a little East today, tomorrow West to gather a little, to use, always a little confused.

In the blog Park saw an old good article, teach us to take notes, but to finish the notes or to remember to summarize oh.

Come on, let's sum it up, today we'll look at how git remote repositories are built.

Of course, using Git, the first step must be to create a new Git repository, there has to be a space to operate it, paddle.

1. Initialize an empty git repository

1 software@debian:~$ mkdir Yafeng
2 software@debian:~$ cd yafeng/
3 software@debian:~/yafeng$ ls
4 software@debian:~/yafeng$ git init
5 Initialized empty git repository in/home/software/yafeng/.git/

Command comments:

In the above command, the actual initialization is the fourth line of the sentence---git init

Of course, there are many students will see Add parameter--bare command, this command will be in our later to explain to you, for not as a shared warehouse, but as a warehouse of their own operations, above this is enough.

OK, now the Yafeng directory is our stronghold---git repository oh.

Below we always have to do something about it, into Baoshan always can not look at OH:

2. Submit the documents we wrote to the warehouse

1 software@debian:~/yafeng$ echo "Our first git repository" >> file
2 software@debian:~/yafeng$ ls
3 file
  4 software@debian:~/yafeng$ git Add file
5 software@debian:~/yafeng$ git commit-m "The first file to commit" file< c4/>6 [Master (root-commit) 0c72641] The first file to commit
7  1 files changed, 1 insertions (+), 0 deletions (-) 
  8  Create mode 100644 file

Command explanation:
We created a new file in the repository as our sample file.

Line 4th: Add the file's information to the GIT repository's index library, and it's not actually added to the library. Of course the file in the example above is just our example, it's a path, so it can be a file, and it can be a directory.

Line 5th: Submit the contents of the index library to the Git repository. After this step the file is actually submitted to the pull Git repository. The contents of the double quotes are based on the different contents of each modification, which we fill out by ourselves,

A lot of people will see

Git commit-a-M ""

This command is used to commit after you have already add one or more files and then modify the files.

Well, anyway, it finally commits the file to the library. But now the warehouse is just a local warehouse, our goal is to become a remote warehouse Oh, go on.

3. Add a remote repository to the local repository and trace the local master branch to the remote branch

1 software@debian:~/yafeng$ git Remote add Origin ssh://software@172.16.0.30/~/yafeng/.git
2 software@debian:~/ yafeng$ git push Origin master
3 software@172.16.0.30 ' s password: 
4 everything up-to-date

Command comments:

Line 1th: Add a remote repository to the local repository, and of course the address behind SSH is the address of our local repository.

Line 2nd: Trace the local master branch to the remote branch, and at the beginning of the GIT repository there will be a default master branch, which you can follow in the same way if you set up another branch.

For the branch of things, we will be careful in the future to tell.

Did you pull this step? I'm telling you, you've done your purpose. Oh, now the GIT repository is a remote repository,

Don't you believe it? Let's test it once:

4. Testing

Now take a look on this machine:

1 software@debian:~/yafeng$ git remote show Origin
 2 software@172.16.0.30 ' s password: 
 3 * Remote Origin
 4
  fetch url:ssh://software@172.16.0.30/~/yafeng/.git
 5   Push  Url:ssh://software@172.16.0.30/~/yafeng /.git
 6   HEAD branch:master
 7   Remote Branch:
 8     Master tracked
 9   Local ref configured for ' git push ':
ten     master pushes to master

Code Comment:

Line 1th: Show remote information

Many see this still will not agree, this can explain what? Well, then, let's do something practical:

On the other machine, the remote clone

 1 root@yafeng-virtualbox:~# ls 2 bin gittest read_temp 3 root@yafeng-virtualbox:~# git clone ssh:
 Software@172.16.0.30/~/yafeng/.git 4 cloning into Yafeng ...
 5 software@172.16.0.30 ' s password:6 remote:counting objects:9, done.
 7 remote:compressing objects:100% (3/3), done.
8 remote:total 9 (Delta 0), reused 0 (Delta 0) 9 receiving objects:100% (9/9), done. Ten root@yafeng-virtualbox:~# ls one bin gittest read_temp yafeng root@yafeng-virtualbox:~# cd YAFENG/13 root@yafeng- virtualbox:~/yafeng# ls 

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.