Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify remote Warehouse address by Git

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The company moved, and the IP address of the server used as the git warehouse has changed. There is a lot of local code, and it takes too much time to check it out again. Can you modify a configuration to associate my local warehouse with the new remote warehouse? the answer is yes!

There are many ways, which are briefly introduced here:

The following take the project git_test as an example:

Old address: http://192.168.1.12:9797/john/git_test.git

New address: http://192.168.100.235:9797/john/git_test.git

Remote warehouse name: origin

Method 1 modify the remote address directly through the command

Enter the git_test root directory

Git remote view all remote warehouses, git remote xxx view specified remote warehouse address git remote set-url origin http://192.168.100.235:9797/john/git_test.git

Method 2 delete and then add remote warehouse by command

Enter the git_test root directory

Git remote view all remote warehouses, git remote xxx view specified remote warehouse address git remote rm origingit remote add origin http://192.168.100.235:9797/john/git_test.git

Method 3 directly modify the configuration file

Enter git_test/.git

Vim config [core] repositoryformatversion = 0 filemode = true logallrefupdates = true precomposeunicode = true [remote "origin"] url = http://192.168.100.235:9797/shimanqiang/assistant.git fetch = + refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master

Just modify the url under [remote "origin"].

Method 4 is modified by a third-party git client.

Take SourceTree as an example, click Warehouse-> Warehouse configuration-> remote Warehouse to manage all the remote warehouses configured in this project, and you can also click to edit the configuration file at the bottom of this interface, which can also be completed in method 3.

Git remote warehouse management

To collaborate on any Git project, you must understand how to manage remote repositories. Remote repositories are project repositories hosted on the network. There may be many, some of which you can only read and some that you can write. When collaborating with others on a project, you need to manage these remote warehouses to push or pull data and share their progress. Manage remote warehouses, including adding remote libraries, removing abandoned remote libraries, managing branches of various remote libraries, defining whether to track these branches, and so on. In this section, we will discuss in detail the management and use of remote libraries.

View the current remote library

To see which remote repositories are currently configured, use the git remote command, which lists the short names of each remote repository. After cloning a project, you can see at least one remote library named origin, which Git uses 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 delta), done. Remote: Total 595 (delta 253), reused 589 (delta 253) Receiving objects: 100% (595delta 595), 73.31 KiB | 1 KiB/s, done. Resolving deltas: 100% (255) Done. $cd ticgit $git remote origin can also add the-v option to display the corresponding clone address: $git remote-v origin git://github.com/schacon/ticgit.git if there are multiple remote repositories, 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 makes it very easy for me to pull their submissions locally from these users' repositories. Please note that only origin uses SSH URL links in the address listed above, so it is only this warehouse that I can push data onto (we will explain why in Chapter 4).

Add remote warehouse

To add a new remote repository, 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 refer to the corresponding warehouse address with the string pb. For example, to grab all the information that Paul has but does not have in the local warehouse, you can run git fetch pb:

$git fetch pb remote: Counting objects: 58, done. Remote: Compressing objects: 100% (41 delta 41), done. Remote: Total 44 (delta 24), reused 1 (delta 0) Unpacking objects: 100% (44 Unpacking objects), done. From git://github.com/paulboone/ticgit * [new branch] master-> pb/master * [new branch] ticgit-> pb/ticgit

Now that the master of Paul is fully accessible locally, the corresponding name is pb/master. You can merge it into one of your own branches, or switch to this branch to see if there are any interesting updates.

Grab data from a remote warehouse

As you saw earlier, you can grab data locally from the remote warehouse with the following command:

$git fetch [remote-name] this command will pull all data from the remote warehouse that is not available in your local warehouse. After running, you can access all the branches in the remote warehouse locally, merge one of them locally, or just take out a branch and find out. We will discuss the concept and operation of branching in detail in Chapter 3.

If a repository is cloned, this command automatically assigns the remote repository to origin. So, git fetch origin grabs all updates uploaded to this remote repository since your last clone (or updates submitted by someone else since the last fetch). It is important to remember that the fetch command only pulls remote data to the local warehouse and does not automatically merge into the current working branch. It can only be merged manually when you are really ready. (to be clear: you need to create a remote warehouse in advance, and then execute: git remote add [warehouse name] [warehouse url], git fetch [remote warehouse name], you can grab the remote warehouse data to the local location, and then use git merge remotes/ [warehouse name] / master to merge the remote warehouse to the local current branch. This branching approach is more suitable for independent-integrated development, that is, separate development and testing and then integrated together. For example, Framework and AP development of Android.

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-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 the branch of a remote warehouse (see the following section and Chapter 3), you can use the git pull command to grab the data automatically, and then automatically merge the remote branch into the current branch in the local warehouse. We often use this in our daily work, which is both fast and good. In fact, by default, the git clone command essentially automatically creates a local master branch to track the master branch in the remote repository (assuming the remote warehouse does have a master branch). So we usually run git pull to grab data from the remote repository of the original clone and merge it into the current branch of the working directory.

Push data to a remote warehouse

At a stage of the project, to share the current results with others, the data from the local warehouse can be pushed 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 automatically uses the default master and origin names), you can run the following command:

This command will complete the task on schedule only if git push origin master has write permission on the cloned server, or no one else is pushing data at the same time. If someone else has pushed several updates before you push the data, your push operation will be rejected. You must grab their updates locally and into your own project before you can push them again. For more information about pushing data to a remote warehouse, see Chapter 3.

View remote warehouse information

We can view the details of a remote warehouse by calling git remote show [remote-name]. For example, to see the cloned origin repository, you can 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 gives a lot of additional information in addition to the corresponding clone address. It kindly tells you that if you are in a master branch, you can use the git pull command to grab data and merge it locally. In addition, all the remote branches in the tracking state are listed.

In actual use, the information given 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 tells us what branches are pushed by default when running git push. It also shows which remote branches have not been synchronized to the local caching, which remote branches have been deleted from the remote server, and which branches will be automatically merged when running git pull (issues and master branches listed in the first four lines). (this command can also view the correspondence between the local branch and the remote warehouse branch.)

Deletion and renaming of remote warehouse

In the new version of Git, you can use the git remote rename command to modify the short name of a remote repository. For example, if you want to change pb to paul, you can run it as follows:

$git remote rename pb paul $git remote origin

Paul note that renaming the remote repository will also change the corresponding branch name, and the original pb/master branch is now paul/master.

If the remote repository server is migrated, or the original clone image is no longer used, or a participant no longer contributes code, then you need to remove the corresponding remote repository and run the git remote rm command:

$git remote rm paul $git remote origin

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report