git modifies the remote warehouse address
There are three kinds of methods:
1. Modify the command
Git remote origin set-url [url]
2. Delete First and then add
Git remote RM origin
git remote add origin [url]
3. Modify config file directly
git remote warehouse management
To participate in the collaboration of any Git project, you must understand how to manage a remote repository. A remote repository is a project warehouse hosted on a network, and there may be several, some of which you can only read and others to write. When you collaborate with others to develop a project, you need to manage these remote warehouses to push or pull data, Share their work progress. Manage remote warehouses, 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 warehouses are currently configured, you can use the GIT remote command, which lists the short names of each remote library. After you have cloned a project, you can at least see a remote library named origin, which is used by git 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)
Receiving objects:100% (595/595), 73.31 KiB | 1 kib/s, done.
Resolving deltas:100% (255/255), done.
$ CD Ticgit
$ git remote
Origin can also add the-V option (this is a shorthand for verbose, take the first letter) and display the corresponding clone address:
$ git remote-v
Origin Git://github.com/schacon/ticgit.git If there are multiple remote warehouses, this command will 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 Git@github.com:mojombo/grit.git As a result, I can easily pull their submissions from these users ' warehouses to the local. Please note that the address listed above is only origin with an SSH URL link. So there's only this warehouse I can push the data up (we'll explain why in the fourth chapter).
Add Remote Warehouse
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
PB Git://github.com/paulboone/ticgit.git can now use string PB to refer to the corresponding warehouse address. For example, to crawl all the information that Paul has, but not the local repository, 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 Backbone branch (master) is fully accessible locally, with the name Pb/master, you can merge it into one of your own branches, or switch to this branch, See what interesting updates there are.
Fetching data from a remote warehouse
As you've seen before, you can crawl data from a remote warehouse to local using the following command:
$ git fetch [remote-name] This command will go to the remote repository to pull all the data not yet in your local warehouse. Once the run is complete, you can access all the branches in the remote repository locally, merge one of the branches locally, or just take out a branch. (We'll discuss the concept and operation of branching in detail in Chapter three.)
If a warehouse is cloned, this command automatically attributes the remote repository to Origin. So, GIT fetch origin crawls all the updates that others have uploaded to this remote repository since your last clone (or someone else has submitted it since the last fetch). It's important to remember that The fetch command simply pulls the remote data to the local repository and does not automatically merge to the current work branch, only if you are really ready to merge manually. (Note: You need to create a remote warehouse beforehand, and then execute: git-remote add [warehouse name] [Warehouse url],git fetch [remote warehouse name], you can crawl to remote warehouse data to local, and then use git merge remotes/[warehouse name]/ Master can merge the remote repository into the local current branch. This branching method is more suitable for independent-integrated development, i.e., the development of the test and then integrated together. For example, the Android framework and AP Development.
You can use the--bare option to run git init to set up an empty warehouse, which initializes a warehouse that does not contain a working directory.
$ cd/opt/git
$ mkdir Project.git
$ CD Project.git
$ git--bare init at this point, Join,josie or Jessica can add it as a remote repository and push a branch to upload the first version of the project to the warehouse.
If you set up a branch to track a branch of a remote warehouse (see the next section and chapter III), you can use the git pull command to automatically crawl data down, and then automatically merge the remote branch into the current branch in the local warehouse. We often use it in our daily work, fast and good. In fact, by default The git clone command essentially creates a local master branch that is used to track the master branch in a remote repository (assuming that the remote repository does have a master branch). So normally we run Git pull, the goal is to crawl data from the original cloned remote repository, Merge to the current branch in the working directory.
Push data to remote warehouse
Project to a stage, 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 On the origin server (again, the clone operation automatically uses the default Master and Origin names), you can run the following command:
$ Git push origin master only has write permission on the cloned server, or if no one else is pushing the data at the same time, the command completes the task as scheduled. If someone else has pushed a few updates before you push the data, Your push will be dismissed. You must first crawl their updates locally and into their own projects before you can push them again. For more information about pushing data to a remote warehouse, see Chapter Iii.
viewing remote Warehouse Information
We can view the details of a remote warehouse by ordering git remote show [remote-name], such as looking at the cloned Origin warehouse, which can be 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
Ticgit in addition to the corresponding cloning address, it also gives a lot of additional information. It kindly tells you that if you are in the Master branch, you can use git pull command to grab data and merge it locally. All remote branches in the tracking state are also listed.
During the actual use, the information that Git remote show gives may be 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 would 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 it tells us what the default push branch is when you run Git push (the last two lines). It also shows which remote branches are not synchronized to the local (caching branch of line sixth), The remote branch that has been synchronized to the Local has been deleted on the remote server (stale tracking branches two branches below) and which branches will be merged automatically when you run Git pull (the issues and master branches listed in the first four lines). (This command can also view the corresponding relationship to the local branch and Remote Warehouse branch.)
Removal and renaming of remote warehouses
In the new git, you can use the GIT remote rename command to modify the short name of a remote warehouse, such as to change the PB to Paul, so that you can run:
$ git remote rename PB paul
$ git remote
Origin
Paul notes that renaming a remote warehouse also causes the corresponding branch name to change, and the original Pb/master branch is now Paul/master.
If you encounter a remote warehouse server migration, or if the original clone image is no longer in use, or if a participant no longer contributes code, you need to remove the corresponding remote warehouse and run the GIT remote RM command:
$ git remote RM Paul
$ git remote
Origin