Getting a remote when trying a local repo

General situation:

deployer$ git clone git://gitserver/project.git
deployer$ cd project
deployer$ ./deploy
Lots of errors!
deployer$ hack --until-it-works deploy
deployer$ git commit -m "fixed it" deploy

      

Oops, now I can't press because I deployment-account

don't have the correct keys. So, back to my account.

larsmans$ cd /tmp
larsmans$ git clone /path/to/deployed/project
larsmans$ cd project

      

But now I cannot push because the remote is not set to the original clone remote.

larsmans$ git remote -v
origin  /path/to/deployed/project/ (fetch)
origin  /path/to/deployed/project/ (push)

      

Can I clone a local directory and get remote objects? I could easily write a script to do this, but maybe Git has a built-in interface. I could not find a matching parameter in git-clone(1)

; --mirror

didn't do the trick.

+3


source to share


1 answer


Don't write scripts because you don't do it more than once for each project (and person)!

In fact, you almost certainly have a local repository when you get into this situation, don't you? Then the last thing you want to do is a new clone.

Instead, just git remote add deployed /path/to/deployed/project

in your existing regular workspace git fetch deployed

and do whatever you want with deployed/master

( refs/remotes/deployed/master

) - you can click it directly on origin

or check it out or merge

this or merge --rebase

that or anything.



Note that if you can ssh to the server and run git there (which you can if you hack there), you can also git from there over the ssh protocol. And this is efficient because the ssh protocol just runs git on the remote side and talks to it with the same git protocol, only it is tunneled through ssh. Therefore, on your local computer, you can git remote add deployed host:/path/to/deployed/project

; it prefers to have host

it configured in .ssh/config

with a fully qualified hostname, username and public key, but it user@host

works as well.

On a production server, I would recommend going back to a previous revision, fixing it elsewhere, and pushing again to limit downtime. For testing and pre-production this is certainly fine.

+4


source







All Articles