Push git branch to other repositoryHow to remove local (untracked) files from the current Git working tree?What is the difference between 'git pull' and 'git fetch'?Make an existing Git branch track a remote branch?How do I undo the most recent commits in Git?Move the most recent commit(s) to a new branch with GitHow do I check out a remote Git branch?How do I delete a Git branch both locally and remotely?How do I push a new local branch to a remote Git repository and track it too?How to revert a Git repository to a previous commitHow do I rename a local Git branch?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
Time travel short story where a man arrives in the late 19th century in a time machine and then sends the machine back into the past
Is it correct to write "is not focus on"?
What is difference between behavior and behaviour
What would happen if the UK refused to take part in EU Parliamentary elections?
apt-get update is failing in debian
The baby cries all morning
Can a monster with multiattack use this ability if they are missing a limb?
Do there exist finite commutative rings with identity that are not Bézout rings?
Lay out the Carpet
Efficiently merge handle parallel feature branches in SFDX
How will losing mobility of one hand affect my career as a programmer?
Why are on-board computers allowed to change controls without notifying the pilots?
Is the destination of a commercial flight important for the pilot?
How does it work when somebody invests in my business?
Can somebody explain Brexit in a few child-proof sentences?
Is this Spell Mimic feat balanced?
Increase performance creating Mandelbrot set in python
How can I use the arrow sign in my bash prompt?
Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?
What is the oldest known work of fiction?
Bash method for viewing beginning and end of file
How do we know the LHC results are robust?
(Bedrock Edition) Loading more than six chunks at once
Push git branch to other repository
How to remove local (untracked) files from the current Git working tree?What is the difference between 'git pull' and 'git fetch'?Make an existing Git branch track a remote branch?How do I undo the most recent commits in Git?Move the most recent commit(s) to a new branch with GitHow do I check out a remote Git branch?How do I delete a Git branch both locally and remotely?How do I push a new local branch to a remote Git repository and track it too?How to revert a Git repository to a previous commitHow do I rename a local Git branch?
I have the following use case:
We have a private gitlab
repository and want to push to a public github
repo to open source it. But the private repository and the public repository shall contain different versions of some files. E.g. different documentation, etc...
I have tried to push the opensource_branch from the private gitlab
repo to the public github
repo:
git push origin_github opensource_branch:master
But the result is that all other historical commits before are also pushed (which contain documentation which shall not be public).
Any ideas how to solve this without manually copy & paste all the time?
Thanks.
PS: I have of course searched SO for similar use cases but did not find exactly this one. Every other question regarding pushing to other remotes does not have the requirement that particular historic commits shall not be visible on the remote at all.
git repository git-branch git-push git-remote
add a comment |
I have the following use case:
We have a private gitlab
repository and want to push to a public github
repo to open source it. But the private repository and the public repository shall contain different versions of some files. E.g. different documentation, etc...
I have tried to push the opensource_branch from the private gitlab
repo to the public github
repo:
git push origin_github opensource_branch:master
But the result is that all other historical commits before are also pushed (which contain documentation which shall not be public).
Any ideas how to solve this without manually copy & paste all the time?
Thanks.
PS: I have of course searched SO for similar use cases but did not find exactly this one. Every other question regarding pushing to other remotes does not have the requirement that particular historic commits shall not be visible on the remote at all.
git repository git-branch git-push git-remote
add a comment |
I have the following use case:
We have a private gitlab
repository and want to push to a public github
repo to open source it. But the private repository and the public repository shall contain different versions of some files. E.g. different documentation, etc...
I have tried to push the opensource_branch from the private gitlab
repo to the public github
repo:
git push origin_github opensource_branch:master
But the result is that all other historical commits before are also pushed (which contain documentation which shall not be public).
Any ideas how to solve this without manually copy & paste all the time?
Thanks.
PS: I have of course searched SO for similar use cases but did not find exactly this one. Every other question regarding pushing to other remotes does not have the requirement that particular historic commits shall not be visible on the remote at all.
git repository git-branch git-push git-remote
I have the following use case:
We have a private gitlab
repository and want to push to a public github
repo to open source it. But the private repository and the public repository shall contain different versions of some files. E.g. different documentation, etc...
I have tried to push the opensource_branch from the private gitlab
repo to the public github
repo:
git push origin_github opensource_branch:master
But the result is that all other historical commits before are also pushed (which contain documentation which shall not be public).
Any ideas how to solve this without manually copy & paste all the time?
Thanks.
PS: I have of course searched SO for similar use cases but did not find exactly this one. Every other question regarding pushing to other remotes does not have the requirement that particular historic commits shall not be visible on the remote at all.
git repository git-branch git-push git-remote
git repository git-branch git-push git-remote
asked Mar 7 at 11:58
DarkoDarko
5,26552135
5,26552135
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Git is based on hashes. It means that the integrity is preserved along with each commit.
A commit is linked to its parent, that's why you often see graphs of Git log with arrows pointing to the previous commit (which does not seem intuitive). In your case you may have an history like this:
$ git log --graph --oneline
* f329c58 Fix (HEAD -> master)
* 9d13dc2 Another fix
* 5641ac5 Spelling
* 978e43c Remove private documentation
* 4837aab Fix code
...
* 1bcd23a Initial commit
What you want to push on the remote repository is only from 978e43c
. Unfortunately this commit has a parent which is 4837aab
. You cannot hide it neither tell Git to not push all the history before.
Solution 1: Rebase on an orphan branch
One solution is to make the commit 978e43c
an orphan, said differently: with no parent.
git checkout --orphan public
git rm -rf . # Clear the working directory
git commit --allow-empty -m "Initial commit"
git rebase master..978e43c
Then you will have a whole new branch which does not include your private documentation.
This solution works but it has several drawback:
Solution 2: Alter history with git filter-branch
You can simply remove your sensitive documentation from the whole history with:
export PRIVATE ./documentation/private-api
git filter-branch -f
--prune-empty
--tag-name-filter cat
--tree-filter 'rm -rf $PRIVATE'
-- --all
add a comment |
You can create a new branch from opensource_branch without inheriting its commits. git checkout
has an option --orphan
to create such a branch. Remove the private files and folders, commit and then push.
git checkout --orphan new_branch opensource_branch
# delete the private files
git rm -rf <private_folders_files>
git commit -m 'the first commit of new_branch'
# publish new_branch to github
git push origin_github new_branch:master
If you will apply commits from opensource_branch to new_branch in future, be careful not to introduce the private files.
Thanks ElpieKay, but it seems that there is no git branch --orphan command. nowox got it right, it's git checkout --orphan.
– Darko
Mar 7 at 13:05
@Darko Sorry, I made a typo. It should begit checkout
instead ofgit branch
.
– ElpieKay
Mar 7 at 13:06
add a comment |
Not sure if this will solve your exact issue, but you could try squashing the commits after you've pushed?
This just squashes multiple commits into one, it does not remove private documents out of the repository.
– Darko
Mar 7 at 13:07
Oh, apologies. I misread your post and assumed your issue was the fact that someone could look at the history of commits to see the deleted/removed private documents.
– hhami
Mar 7 at 15:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043246%2fpush-git-branch-to-other-repository%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Git is based on hashes. It means that the integrity is preserved along with each commit.
A commit is linked to its parent, that's why you often see graphs of Git log with arrows pointing to the previous commit (which does not seem intuitive). In your case you may have an history like this:
$ git log --graph --oneline
* f329c58 Fix (HEAD -> master)
* 9d13dc2 Another fix
* 5641ac5 Spelling
* 978e43c Remove private documentation
* 4837aab Fix code
...
* 1bcd23a Initial commit
What you want to push on the remote repository is only from 978e43c
. Unfortunately this commit has a parent which is 4837aab
. You cannot hide it neither tell Git to not push all the history before.
Solution 1: Rebase on an orphan branch
One solution is to make the commit 978e43c
an orphan, said differently: with no parent.
git checkout --orphan public
git rm -rf . # Clear the working directory
git commit --allow-empty -m "Initial commit"
git rebase master..978e43c
Then you will have a whole new branch which does not include your private documentation.
This solution works but it has several drawback:
Solution 2: Alter history with git filter-branch
You can simply remove your sensitive documentation from the whole history with:
export PRIVATE ./documentation/private-api
git filter-branch -f
--prune-empty
--tag-name-filter cat
--tree-filter 'rm -rf $PRIVATE'
-- --all
add a comment |
Git is based on hashes. It means that the integrity is preserved along with each commit.
A commit is linked to its parent, that's why you often see graphs of Git log with arrows pointing to the previous commit (which does not seem intuitive). In your case you may have an history like this:
$ git log --graph --oneline
* f329c58 Fix (HEAD -> master)
* 9d13dc2 Another fix
* 5641ac5 Spelling
* 978e43c Remove private documentation
* 4837aab Fix code
...
* 1bcd23a Initial commit
What you want to push on the remote repository is only from 978e43c
. Unfortunately this commit has a parent which is 4837aab
. You cannot hide it neither tell Git to not push all the history before.
Solution 1: Rebase on an orphan branch
One solution is to make the commit 978e43c
an orphan, said differently: with no parent.
git checkout --orphan public
git rm -rf . # Clear the working directory
git commit --allow-empty -m "Initial commit"
git rebase master..978e43c
Then you will have a whole new branch which does not include your private documentation.
This solution works but it has several drawback:
Solution 2: Alter history with git filter-branch
You can simply remove your sensitive documentation from the whole history with:
export PRIVATE ./documentation/private-api
git filter-branch -f
--prune-empty
--tag-name-filter cat
--tree-filter 'rm -rf $PRIVATE'
-- --all
add a comment |
Git is based on hashes. It means that the integrity is preserved along with each commit.
A commit is linked to its parent, that's why you often see graphs of Git log with arrows pointing to the previous commit (which does not seem intuitive). In your case you may have an history like this:
$ git log --graph --oneline
* f329c58 Fix (HEAD -> master)
* 9d13dc2 Another fix
* 5641ac5 Spelling
* 978e43c Remove private documentation
* 4837aab Fix code
...
* 1bcd23a Initial commit
What you want to push on the remote repository is only from 978e43c
. Unfortunately this commit has a parent which is 4837aab
. You cannot hide it neither tell Git to not push all the history before.
Solution 1: Rebase on an orphan branch
One solution is to make the commit 978e43c
an orphan, said differently: with no parent.
git checkout --orphan public
git rm -rf . # Clear the working directory
git commit --allow-empty -m "Initial commit"
git rebase master..978e43c
Then you will have a whole new branch which does not include your private documentation.
This solution works but it has several drawback:
Solution 2: Alter history with git filter-branch
You can simply remove your sensitive documentation from the whole history with:
export PRIVATE ./documentation/private-api
git filter-branch -f
--prune-empty
--tag-name-filter cat
--tree-filter 'rm -rf $PRIVATE'
-- --all
Git is based on hashes. It means that the integrity is preserved along with each commit.
A commit is linked to its parent, that's why you often see graphs of Git log with arrows pointing to the previous commit (which does not seem intuitive). In your case you may have an history like this:
$ git log --graph --oneline
* f329c58 Fix (HEAD -> master)
* 9d13dc2 Another fix
* 5641ac5 Spelling
* 978e43c Remove private documentation
* 4837aab Fix code
...
* 1bcd23a Initial commit
What you want to push on the remote repository is only from 978e43c
. Unfortunately this commit has a parent which is 4837aab
. You cannot hide it neither tell Git to not push all the history before.
Solution 1: Rebase on an orphan branch
One solution is to make the commit 978e43c
an orphan, said differently: with no parent.
git checkout --orphan public
git rm -rf . # Clear the working directory
git commit --allow-empty -m "Initial commit"
git rebase master..978e43c
Then you will have a whole new branch which does not include your private documentation.
This solution works but it has several drawback:
Solution 2: Alter history with git filter-branch
You can simply remove your sensitive documentation from the whole history with:
export PRIVATE ./documentation/private-api
git filter-branch -f
--prune-empty
--tag-name-filter cat
--tree-filter 'rm -rf $PRIVATE'
-- --all
edited Mar 7 at 12:22
answered Mar 7 at 12:16
nowoxnowox
6,804937107
6,804937107
add a comment |
add a comment |
You can create a new branch from opensource_branch without inheriting its commits. git checkout
has an option --orphan
to create such a branch. Remove the private files and folders, commit and then push.
git checkout --orphan new_branch opensource_branch
# delete the private files
git rm -rf <private_folders_files>
git commit -m 'the first commit of new_branch'
# publish new_branch to github
git push origin_github new_branch:master
If you will apply commits from opensource_branch to new_branch in future, be careful not to introduce the private files.
Thanks ElpieKay, but it seems that there is no git branch --orphan command. nowox got it right, it's git checkout --orphan.
– Darko
Mar 7 at 13:05
@Darko Sorry, I made a typo. It should begit checkout
instead ofgit branch
.
– ElpieKay
Mar 7 at 13:06
add a comment |
You can create a new branch from opensource_branch without inheriting its commits. git checkout
has an option --orphan
to create such a branch. Remove the private files and folders, commit and then push.
git checkout --orphan new_branch opensource_branch
# delete the private files
git rm -rf <private_folders_files>
git commit -m 'the first commit of new_branch'
# publish new_branch to github
git push origin_github new_branch:master
If you will apply commits from opensource_branch to new_branch in future, be careful not to introduce the private files.
Thanks ElpieKay, but it seems that there is no git branch --orphan command. nowox got it right, it's git checkout --orphan.
– Darko
Mar 7 at 13:05
@Darko Sorry, I made a typo. It should begit checkout
instead ofgit branch
.
– ElpieKay
Mar 7 at 13:06
add a comment |
You can create a new branch from opensource_branch without inheriting its commits. git checkout
has an option --orphan
to create such a branch. Remove the private files and folders, commit and then push.
git checkout --orphan new_branch opensource_branch
# delete the private files
git rm -rf <private_folders_files>
git commit -m 'the first commit of new_branch'
# publish new_branch to github
git push origin_github new_branch:master
If you will apply commits from opensource_branch to new_branch in future, be careful not to introduce the private files.
You can create a new branch from opensource_branch without inheriting its commits. git checkout
has an option --orphan
to create such a branch. Remove the private files and folders, commit and then push.
git checkout --orphan new_branch opensource_branch
# delete the private files
git rm -rf <private_folders_files>
git commit -m 'the first commit of new_branch'
# publish new_branch to github
git push origin_github new_branch:master
If you will apply commits from opensource_branch to new_branch in future, be careful not to introduce the private files.
edited Mar 7 at 13:06
answered Mar 7 at 12:10
ElpieKayElpieKay
8,83821023
8,83821023
Thanks ElpieKay, but it seems that there is no git branch --orphan command. nowox got it right, it's git checkout --orphan.
– Darko
Mar 7 at 13:05
@Darko Sorry, I made a typo. It should begit checkout
instead ofgit branch
.
– ElpieKay
Mar 7 at 13:06
add a comment |
Thanks ElpieKay, but it seems that there is no git branch --orphan command. nowox got it right, it's git checkout --orphan.
– Darko
Mar 7 at 13:05
@Darko Sorry, I made a typo. It should begit checkout
instead ofgit branch
.
– ElpieKay
Mar 7 at 13:06
Thanks ElpieKay, but it seems that there is no git branch --orphan command. nowox got it right, it's git checkout --orphan.
– Darko
Mar 7 at 13:05
Thanks ElpieKay, but it seems that there is no git branch --orphan command. nowox got it right, it's git checkout --orphan.
– Darko
Mar 7 at 13:05
@Darko Sorry, I made a typo. It should be
git checkout
instead of git branch
.– ElpieKay
Mar 7 at 13:06
@Darko Sorry, I made a typo. It should be
git checkout
instead of git branch
.– ElpieKay
Mar 7 at 13:06
add a comment |
Not sure if this will solve your exact issue, but you could try squashing the commits after you've pushed?
This just squashes multiple commits into one, it does not remove private documents out of the repository.
– Darko
Mar 7 at 13:07
Oh, apologies. I misread your post and assumed your issue was the fact that someone could look at the history of commits to see the deleted/removed private documents.
– hhami
Mar 7 at 15:52
add a comment |
Not sure if this will solve your exact issue, but you could try squashing the commits after you've pushed?
This just squashes multiple commits into one, it does not remove private documents out of the repository.
– Darko
Mar 7 at 13:07
Oh, apologies. I misread your post and assumed your issue was the fact that someone could look at the history of commits to see the deleted/removed private documents.
– hhami
Mar 7 at 15:52
add a comment |
Not sure if this will solve your exact issue, but you could try squashing the commits after you've pushed?
Not sure if this will solve your exact issue, but you could try squashing the commits after you've pushed?
answered Mar 7 at 12:12
hhamihhami
112
112
This just squashes multiple commits into one, it does not remove private documents out of the repository.
– Darko
Mar 7 at 13:07
Oh, apologies. I misread your post and assumed your issue was the fact that someone could look at the history of commits to see the deleted/removed private documents.
– hhami
Mar 7 at 15:52
add a comment |
This just squashes multiple commits into one, it does not remove private documents out of the repository.
– Darko
Mar 7 at 13:07
Oh, apologies. I misread your post and assumed your issue was the fact that someone could look at the history of commits to see the deleted/removed private documents.
– hhami
Mar 7 at 15:52
This just squashes multiple commits into one, it does not remove private documents out of the repository.
– Darko
Mar 7 at 13:07
This just squashes multiple commits into one, it does not remove private documents out of the repository.
– Darko
Mar 7 at 13:07
Oh, apologies. I misread your post and assumed your issue was the fact that someone could look at the history of commits to see the deleted/removed private documents.
– hhami
Mar 7 at 15:52
Oh, apologies. I misread your post and assumed your issue was the fact that someone could look at the history of commits to see the deleted/removed private documents.
– hhami
Mar 7 at 15:52
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043246%2fpush-git-branch-to-other-repository%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown