Brett
Brett

Reputation: 20049

Changing my Git remote origin temporarily

I currently have a repo, but I want to temporarily use another repo to push the changes to and then when I choose to, change back to the other repo and push to that one again (this is due to reasons of access to the main repo).

So I'm wondering, if I want to change the repo the pushes go to, is all I have to do is change the origin in my git config file, such as:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[remote "origin"]
    url = [email protected]:myname/my-repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

Do I just change this line:

url = [email protected]:myname/my-repo.git

...to the new value and then back again to go back to the main repo? ...or is there something else to do and if so, what!?

Upvotes: 3

Views: 2082

Answers (2)

ensc
ensc

Reputation: 6984

you can push and pull directly to/from a remote repository:

git push [email protected]:myname/my-other-repo.git HEAD:refs/heads/foo
git pull [email protected]:myname/my-other-repo.git refs/heads/foo

Upvotes: 7

Kombajn zbożowy
Kombajn zbożowy

Reputation: 10693

As a distributed version control system, Git allows you to manage multiple remote repositories. If it's just temporary, don't touch your origin - just add a separate remote. And don't bother with editing config files, use the command line:

git remote add temp [email protected]:myname/my-other-repo.git

Push to a new remote using:

git push temp

After access issues are solved synchronize origin:

git push origin

Read more about git remote here: https://git-scm.com/docs/git-remote.

Upvotes: 5

Related Questions