2

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 git@git.someDomain.com. Under ~/git/ I have many directories (myDir1, myDir2, myDirN...) holding code which I have obtained doing:

  1. git clone git@git.someDomain.com:my-repo-1
  2. git clone git@git.someDomain.com: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:

  1. How do I push this local repo to git@git.someDomain.com:my-repo-1 ?
  2. How do I get the content of ~/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.

cross
  • 1,018
  • 13
  • 32

1 Answers1

2

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 git@git.someDomain.com:my-repo-1 ?

cd ~/scripts
git remote add origin git@git.someDomain.com: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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • can't I get _the content of ~/scripts (the newly pushed branch) in the ~/someScripts on my other PC_ by doing some `git clone` operation? – cross Jun 02 '15 at 21:11
  • If both PC see each other, with for example a shared folder, then yes, a git clone is possible. – VonC Jun 02 '15 at 21:30
  • what will be the name of the orphaned branch for `git remote add origin git@git.someDomain.com:my-repo-1` , how can I name it, for example, "scrtipts" – cross Jun 03 '15 at 08:55