72

I have one repo in github which is public, there I have an Open source application i'm working on that is for making product catalogs, and small cms content.

I also have a private repository (not hosted in github) which is an application developed under the open source application hosted in github.

Since I'm currently working on both applications, adding features in the open source one and also making changes in the private one like changing the template and also pulling the code from the open source one.

I was wondering if there is any way in which I could pull the new stuff from the open source one but also pushing the code of the new application to the other repo.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
chopi321
  • 1,383
  • 1
  • 11
  • 23

3 Answers3

111

Set a push URL for the remote that is different from the pull URL:

git remote set-url --push origin user@example.com:repo.git

This changes the remote.name.pushurl configuration setting. Then git pull will pull from the original clone URL but git push will push to the other.


In old Git versions, git remote set-url did not have the --push switch. Without it, you have to do this by changing the configuration setting manually:

git config remote.origin.pushurl user@example.com:repo.git
Aristotle Pagaltzis
  • 112,955
  • 23
  • 98
  • 97
  • Somewhat more explicitly : `git remote set-url --push origin user@user.com:repo.git` – diapir Jul 15 '15 at 06:00
  • It would be helpful to know exactly which version of git introduced this feature, so I could easily check if I have it. Does anyone know? – Wildcard Dec 02 '15 at 23:48
  • 3
    The answer is from 2010. You are unlikely to be using any git old enough to lack this feature. [Googling "git" "release notes" "pushurl"](https://google.com/search?q=%22git%22+%22release+notes%22+%22pushurl%22) points at the [1.6.4 release notes](https://www.kernel.org/pub/software/scm/git/docs/RelNotes-1.6.4.txt), and [blame on the `git-config` docs](https://github.com/git/git/blame/0c83680e9c047170614fb08ef222ea4f460e514d/Documentation/config.txt#L2385) points at [this commit](https://github.com/git/git/commit/203462347fce0eab563fe77640648a7e8ae64d3b) which confirms 1.6.4 as earliest release – Aristotle Pagaltzis Dec 04 '15 at 02:06
  • FWIW, [1.6.4 came out on Jul 29, 2009](https://github.com/git/git/releases/tag/v1.6.4), so the feature is 1.5 years older than the answer. – Aristotle Pagaltzis Dec 04 '15 at 02:12
24

git pull private master and git push github master pulls from your private repo (given it's named like that) and pushes to github (might also be called origin). It's not SVN ;-)

Reactormonk
  • 21,472
  • 14
  • 74
  • 123
  • something like git pull will normally pull from the open source since I cloned the repo from github. So the push will be like: git push origin user@user.com:repo.git? – chopi321 Dec 24 '10 at 00:47
  • If the github repo is where you cloned from then that repo is probably `origin` so do what Tass said, but replace `github` with `origin` (and of course, replace `private` with the name of the private repo). See http://www.kernel.org/pub/software/scm/git/docs/git-remote.html – Tyler Dec 24 '10 at 03:24
  • 1
    For my fellow noobs, I just want to point out that in my experience today, you must swap your entire repo url for "github" in "git push github master." – CodeWalrus Apr 30 '14 at 01:10
1

of course! Just get in .git folder and open config file, then edit it, as bellow:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[submodule]
    active = .
[remote "remoteA"]
    url = https://github.com/userA/repoX.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[remote "remoteB"]
    url = https://github.com/userB/repoX.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[pull]
    ff = only
    rebase = true

after this, you can run the following commands as you wish:

> git pull remoteA [branch_nameX]
> git push remoteB [branch_nameY]
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 01 '23 at 22:26