简体   繁体   中英

How to set a git repository's remote url without updating the local repository it's cloned from?

There is no remote repository for this project yet but it has a remote set in its config and someone did that for some reason so I won't change it. The original repository is in /home/me/repo1/.git and I ran git clone /home/me/repo1/.git while in /home/me/repo2 so now it's cloned in /repo2
When I go into the cloned repo and run git remote set-url origin http://example.com/asdf/.git both repositories config's get updated.

I can't fork the repo because I don't have admin access and no access to gh cli or similar tools. Is there a workaround to only update the second repository?

Cannot simulate the issue here, and it makes sense, since the remote tracking configuration is on a per repository basis, could you please check if the performed steps resemble the steps provided below? The intent of the pwd commands is to demonstrate the current folder in which the subsequent commands are executed.

  1. Create repo1
$ pwd
/home/user/
$ mkdir repo1
$ cd repo1
$ git init .
Initialized empty Git repository in /home/daniel/Temporary/repo1/.git/
$ git remote add origin http://url.com/repo1.git
  1. Create repo2
$ pwd
/home/user/
$ mkdir repo2
$ cd repo2
$ git clone ../repo1/.git/
Cloning into 'repo1'...
warning: You appear to have cloned an empty repository.
done.
  1. Set remote url for cloned repository
$ pwd
/home/user/repo2/repo1
$ git remote set-url origin http://url.com/repo2.git

  1. Retrieve the remote urls
$ pwd
/home/user/repo1
$ git remote -v
origin  http://url.com/repo1.git (fetch)
origin  http://url.com/repo1.git (push)

-----

$ pwd
/home/user/repo2/repo1
$ git remote -v
origin  http://url.com/repo2.git (fetch)
origin  http://url.com/repo2.git (push)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM