Git remote repository Management

Source: Internet
Author: User
Tags using git

To participate in collaboration with any git project, you must understand how to manage remote repositories. A remote repository is a project repository hosted on the network. There may be many projects, some of which can only be read and others can be written. when developing a project in collaboration with others, you need to manage these remote repositories to push or pull data and share their work progress. manage remote repositories, including adding remote libraries, removing obsolete remote libraries, managing various remote database branches, and defining whether to track these branches. this section describes how to manage and use remote databases.

View the current remote database

You can use the GIT Remote Command to view which remote repositories are currently configured. It lists the brief names of each remote repository. after cloning a project, you can see at least one remote database named origin. Git uses this name by default to identify the original repository you cloned:

$ 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)

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

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

$ CD ticgit

$ Git remote

You can also add the-V option to the origin to display the corresponding clone address:

$ Git remote-V

Origin git: // github.com/schacon/ticgit.gitif you have multiple remote warehouses, this command will be displayed as follows in the zoogrit project:

$ 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

OriginGit@github.com: mojombo/grit. GitIn this way, I can easily pull their submissions from these users' repositories to the local device. note that the addresses listed above only use ssh url links for origin, so I can push data only for this repository (we will explain the reason in chapter 4 ).

Add remote Repository

To add a new remote repository, you can specify a simple name for future reference and 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

Petabgit: // github.com/paulboone/ticgit.gitnow you can use the string petabyte to refer to the corresponding repository address. For example, to capture all the information that Paul has but does not exist in the local repository, run git fetch Pb:

$ Git fetch Pb

Remote: counting objects: 58, done.

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

Remote: total 44 (delta 24), 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 master branch can be accessed locally. The corresponding name is Pb/master, you can merge it into a branch of your own, or switch to the branch to see some interesting updates.

Capture data from a remote warehouse

As we can see before, you can use the following command to capture data from a remote warehouse to a local machine:

$ Git fetch [Remote-name] This command will pull all the data that is not in your local repository to the remote repository. after running, you can access all the branches in the remote warehouse locally, merge one of them to the local machine, or just retrieve a branch to find out. (we will discuss in detail the concept and operation of the branch in Chapter 3 .)

If a repository is cloned, the remote repository is automatically assigned to the origin. therefore, the GIT fetch origin captures all updates uploaded to this remote repository since your last clone (or updates submitted by others since the last fetch ). it is important to remember that the FETCH command only pulls remote data to a local warehouse and does not automatically merge the data into the current work branch. You can only merge the data manually when it is ready. (Description: You need to create a remote repository in advance, and then execute: git remote add [repository name] [repository url], git fetch [remote repository name], the remote repository data can be captured to the local device, and then the remote repository merge can be directed to the local current branch by using git merge remotes/[repository name]/master. this branch method is suitable for independent-integrated development, that is, after each branch is developed and tested, it is integrated. for example, Android framework and AP development.

Available-- BareRun git init to set an empty repository. This will initialize a repository that does not contain a working directory.

$ CD/opt/git

$ Mkdir project. Git

$ CD project. Git

$ Git -- bare init at this moment, join, Josie or Jessica can add it as a remote repository, push a branch, and then upload the project of the first version to the repository .)

If you have set a branch to track the branch of a remote repository (see the following section and chapter 3), you can use the GIT pull command to automatically capture data, then, the remote branch is automatically merged to the current branch in the local repository. we often use this in our daily work, which is fast and good. in fact, by default, the GIT clone command automatically creates a local master branch to track the master branch in the remote warehouse (assuming that the remote warehouse does have a master branch ). therefore, we generally run git pull to capture data from the original cloned remote repository and merge the data to the current branch in the working directory.

Push data to remote warehouse

The project is in a phase. To share the current results with others, you can push the data in the Local warehouse to the remote warehouse. the command to implement this task is simple: git push [Remote-name] [branch-name]. if you want to push the local master branch to the origin server (again, the clone operation will automatically use the default master and origin names), run the following command:

$ Git push origin master only has the write permission on the cloned server, or no one else is pushing data at the same time, this command will complete the task as scheduled. if you have already pushed several updates before pushing data, your push operation will be rejected. you must first capture their updates to the local device and add them to your project before pushing them again. for details about pushing data to a remote warehouse, see Chapter 3.

View remote Repository Information

Run the GIT remote show [Remote-name] command to view details of a remote repository. For example, to view the cloned origin repository, run:

$ Git remote show origin

* Remote origin

URL: git: // github.com/schacon/ticgit.git

Remote branch merged with 'git pull 'while on Branch master

Master

Tracked remote branches

Master

In addition to the clone address, ticgit provides a lot of additional information. it kindly tells you that if it is in the master branch, you can use the GIT pull command to capture data and merge it to the local. all remote branches in the tracking status are also listed.

In actual use, the information provided by git remote show may look like this:

$ Git remote show origin

* Remote origin

URL:Git@github.com: defunkt/GitHub. Git

Remote branch merged with 'git pull 'while on Branch issues

Issues

Remote branch merged with 'git pull 'while on Branch master

Master

New Remote branches (next fetch will store in remotes/origin)

Caching

Stale tracking branches (use 'git remote prune ')

Libwalker

Walker2

Tracked remote branches

ACL

Apiv2

Dashboard2

Issues

Master

Postgres

Local branch pushed with 'git push'

MASTER: Master, which tells us what the default push branch is when git push is run ). it also shows which remote branches have not been synchronized to the local database ), which remote branches have been synchronized to the local server have been deleted on the remote server, and which branches will be automatically merged when running git pull: issues and master branches listed in the first four rows ). (this command can also view the relationship between the local branch and the remote warehouse branch .)

Delete and rename a remote Repository

In the new version of git, you can use the GIT remote RENAME command to modify the short name of a remote repository. To change PB to Paul, run the following command:

$ Git remote rename Pb Paul

$ Git remote

Origin

Paul note that renaming a remote Repository also changes the name of the corresponding branch. The original Pb/Master branch is now Paul/master.

When a remote repository server is migrated, or the original cloned image is no longer used, or a participant no longer contributesCodeTo remove the corresponding remote repository, run the GIT remote RM command:

$ Git remote RM Paul

$ Git remote

Origin

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.