1

I am using a forked repo as submodule in another repo, and I want to push changes made to that forked repo without triggering a pull request or anything like that. It sounds pretty straight forward but the reason I'm hesitating is because when I try to do that, Git asks me for my username and password even though I have ssh keys set up, leading me to suspect that something is wrong.

So, to simplify:

  • I have the larger repo A
  • I have submodule B which I've forked from another repo
  • I want to make changes to repo B, preferably to an alt branch but not necessarily
  • I do not want any pull request to ever happen to the original authors of repo B. I have forked repo B as a way to have a functional copy as a submodule in repo A. I would like to make branches in repo B to edit hardcoded paths in the scripts for each project I use repo B for, for example, but that's not necessary.

I have considered also creating a branch and pushing to origin/<branch> instead of origin/master, but again, it asks me for the UN/PW, which I do not like. I don't like the possibility that I might accidentally trigger a pull request or somehow modify the original repo, as in the non-forked repo, which I don't want to do. Any advice?

CelineDion
  • 906
  • 5
  • 21
  • you may find checking out your branch with ssh instead of http fixes all your problems – ti7 Aug 03 '21 at 18:16
  • Could you further elaborate? @ti7 – CelineDion Aug 03 '21 at 18:20
  • 1
    there are a [few different protocols](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) for accessing git, and I've found ssh is the least-problematic - if you have the repo(s) checked out with http already and are making changes already (presumably your case), you can [change the remote](https://stackoverflow.com/questions/2432764/how-to-change-the-uri-url-for-a-remote-git-repository) – ti7 Aug 03 '21 at 18:26
  • Thanks. What I ended up doing was switching remote to the ssh url and committing and pushing to an alt branch of the forked repo. I guess I don't know what the point of forks are. I thought they were intended to be a way to copy a repo and modify it independently of the original repo. But then pushing changes to origin is like trying to modify the original repo? and if that's the case, what's the point of a pull request? I guess I need to brush up on forks. – CelineDion Aug 03 '21 at 20:53
  • Remember that a *submodule* is simply a (completely separate) `git clone`: submodules are (currently at least) blissfully unaware of their containing superprojects. So if the push in the submodule is behaving oddly, look at the submodule's configuration, not the superproject's: the superproject's configuration is irrelevant. – torek Aug 04 '21 at 09:56

1 Answers1

0

when I try to do that, Git asks me for my username and password even though I have ssh keys set up,

Check the remote repository URL in your local clone of your fork:

cd /path/to/local/clone
git remote -v

If you see https://, switching to SSH is:

git remote set-url git@github.com:<me>/<myfork>

In both instance, pushing a branch to a fork does not trigger a PR.

You can create a PR directly from your local prompt with gh pr create though.

Note: if that local forked clone is a submoule of a parent project, you would need to update the submodule URL in the parent repo as well:

cd /path/to/parent/repo
git submodule set-url [--] <path> <newurl>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250