Home > front end >  How to push to my open-source library on GitHub, when it's checked out as a submodule of a clos
How to push to my open-source library on GitHub, when it's checked out as a submodule of a clos

Time:10-24

Here's my situation: I'm the maintainer of an open-source library on GitHub, and I also work on various closed-source (non-GitHub-based) git-repositories as part of my employment. Many of these closed-source git repositories link to my open-source library on GitHub as a submodule.

Because of this, it's often the case that I'll be working on one of the closed-source repositories and I'll come across something that I want to change in my open-source library. I'll make the change in the submodule and build and test it, and then I want to commit it and push the change to GitHub... and up until about four months ago that worked fine -- but recently GitHub has tightened their security policies so they no longer accept pushes from https-based repository-checkouts, only from ssh-based ones.

However, the .gitmodules file in my closed-source repositories are all configured to check out the open-source submodule via an https URL (so that my co-workers can git submodule update --init --recursive the submodule without having to know my GitHub login info), which means that GitHub won't let me push my changes.

For clarity, here's the relevant excerpt from one of my .gitmodules files:

[submodule "submodules/muscle"]
    path = submodules/muscle
    url = https://github.com/jfriesne/muscle.git

My work-around has been to keep a separate (ssh-based) checkout of the open source library on my machine, and manually copy any locally-changed files over to that, do a commit-and-push from there, and then go back to my submodule and do a git stash followed by a git pull origin master. That works, but manually copying files is a bit tedious and error-prone. I miss being able to just do a simple cd submodules/muscle ; git commit -mblah ; git push, as I could in the past.

My question is, is there any way to authenticate myself to GitHub so that I can push changes to the https-checked-out submodule directly?

CodePudding user response:

You can still push via https, you just have to use a GitHub "token" (which expires, which means you have to re-generate them now and then and update them, which is a pain).

To access GitHub via ssh even when the URL says https://github.com/<path>, consider using Git's insteadOf feature. This particular feature is a bit confusing to configure, but is straightforward to use once it's done:

git config --global url.ssh://[email protected]/jfriesne/muscle.git.insteadOf https://github.com/jfriesne/muscle.git

The value for the configured option is the URL that will appear in some .git/config file's remote.remote.url entry. The name of the configured option starts with url and ends with insteadOf, and has the usual dots, but between the two dots you insert the replacement URL.

(If your ssh configuration for github.com specifies User git you can omit the git@ from the url.replacement.insteadOf = original setting. The phrasing in the git config documentation is a little confusing since it describes the fully general form, where you replace just a prefix of the URL, keeping the remainder: you can use this to make all github.com accesses use ssh, for instance.)

  • Related