Reputation: 1068
I am new to git
and I am trying to learn some new stuff.
I want to know is it possible to have two branches which are independent of each other (no common ancestor) in the same repo.
Illustrative Example:
Let's imagine we have a repo stored in [email protected]
. Under ~/git/
I have many directories (myDir1
, myDir2
, myDirN
...) holding code which I have obtained doing:
git clone [email protected]:my-repo-1
git clone [email protected]:my-repo-2
and so on...Now I want to move ~/git/myDir1/scripts
to ~/scripts/
because I want to keep those scripts separate from the source code stored in ~/git/myDir1
I go to ~/scripts
and execute git init
thus I create a local repo for those scripts.
And there I get stuck.
Questions:
[email protected]:my-repo-1
?~/scripts
(the newly pushed branch) in the ~/someScripts
on my other PC?I apologize beforehand if I have abused with the git terminology, I am still trying to learn what a branch, remote, origin etc. mean.
Upvotes: 2
Views: 71
Reputation: 1329922
is it possible to have two branches which are independent of each other in the same repo.
In the same repo, that is called an orphaned branch, but that is not what you are doing in your question.
You are trying to split a repo in two, removing a folder history from one repo (~/git/myDir1
, folder scripts/
)and importing its history in a second new repo (~/scripts
)
How do I push this local repo to
[email protected]:my-repo-1
?
cd ~/scripts
git remote add origin [email protected]:my-repo-1
But you will need to have at least one commit before being able to do a git push -u origin master
For that, see Splitting a subfolder out into a new repository
How do I get the content of
~/scripts
(the newly pushed branch) in the~/someScripts
on my other PC?
One solution is to compress your ~/scripts
into one file, a bundle, copy it to your other PC and clone from that git bundle
.
That seems easier (as a quick win) than trying to launch a listener on your other PC (git daemon, sshd, httpd) in order to git push
from one PC to the other: simply copy one file.
Upvotes: 2