Community

Switching from an anonymous checkout to being able to feed back changes directly

Last updated June 28, 2011.

Situation:

You checked out a project from git using the recommended 'anonymous' (http) method, made some changes, and now want to commit back.

  • Either you've now been given write-rights by the maintainer that you didn't have before,
  • or you joined a development process where someone anonymously checked out a project that you do in fact have write access to.

(My case is the second - a team-member installed a sandbox project of mine, and now I'm trying to feed back a fix made locally within that checkout.)

If you try to git push we get told

error: Cannot access URL http://git.drupal.org/sandbox/dman/1104872.git/, return code 22

What's the problem?

This is because the checkout was from a read-only source, and though the local code is still anchored to that as the remote origin, it cannot feed back to it in write mode.
We need to change that URL (the one we cannot write to) into an alternative repository root.
Apparently, it's possible to have multiple 'origins' etc in git, but that is way too complex right now. We just need to switch.

A writeable repository URL is the sort you would see when viewing the Version control tab as a module maintainer. In this case, it looks like

dman@git.drupal.org:sandbox/dman/1104872.git

This is similar, but not the same as the public version
http://git.drupal.org/sandbox/dman/1104872.git

Though it does represent the same content.

A simple, behind-the-scenes switch will probably make things alright.

use git remote set-url

Apparently there is a tool for this (I didn't know when I found the below method)

git remote set-url origin dman@git.drupal.org:sandbox/dman/1104872.git

What this does is apparently equivalent to the manual method here:

Edit the local git config file to point at the writeable location

edit the file .git/config in the project root.

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = http://git.drupal.org/sandbox/dman/1104872.git
[branch "master"]
        remote = origin
        merge = refs/heads/master

Just replace the http: URL with a username@git.drupal.org one.
-       url = http://git.drupal.org/sandbox/dman/1104872.git
+      url = dman@git.drupal.org:sandbox/dman/1104872.git

Push it good

NOW, the local git repo is linked with the writable version on drupal.org as the origin, and you can
git push
to make things happen.

Alternatives

See also: Changing the origin of your git repository

In the old days, I would have just

  • Made a diff patch of the differences
  • Completely deleted the unusable checkout
  • Re-checked-out the same stuff using the proper authentication
  • Re-applied the patch
  • Checked in the changes normally

... which ... also gets the job done, but the point of a version control system is to avoid that sort of mess-around.