0

I have somewhat of a peculiar question (I think...). Bear with me if some of this doesnt make sense; I'm a git noob.

I have an already existing android project that is in its own folder, completely outside of a repo that I cloned. What I want to do is to just push the contents of this android project to my colleague's repo. I want the project to be part of a new branch on the repo. How do I go about doing this? Can I just open bash, go to my android project folder and add a remote to the repo and push to it? Or I guess I first need to make this project into a branch of the repo? If so, how would I make it a branch of the repo if I'm actually working outside of the local repo folder?

Confused yet? ;)

Maybe it makes most sense to just copy the entire project into the local repo folder then create a branch and push it?

I'd love some step-by-step instructions on how to do this most efficiently.

Much obliged.

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
LuxuryMode
  • 33,401
  • 34
  • 117
  • 188
  • have you looked into this? http://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide – WarrenFaith Dec 12 '10 at 17:38

2 Answers2

1

It seems that the two projects are largely independent so I strongly suspect the best option is to change the file structure of your repository rather than using branches:

/path/to/repo
  +- projectA
  +- projectB

So on one machine do this:

mkdir /path/to/repo
git init
cp -r /path/to/projectA .
git add .
git commit -m "Initial import of project A"

Then on the other machine:

cd /path/to
git clone <url for repo set up on the first machine>
cd repo
cp -r /path/to/projectB .
git add .
git commit -m "Initial import of project B"

Don't bother with git branches at this point. You can now work on project A and create commits; the other developer can work on B. There won't be any conflicts and you will both see each other's changes.

I'd also recommend setting up a bare repository somewhere that you both push to and pull from:

mkdir /path/to/centralrepo
git init --bare

You can then both clone this repository. Git is peer-to-peer, but it's kinda nice to have a repository that you designate as "central", especially if you're going to add continuous integration or new developers in future.

It seems that you are a little confused about what a git branch means. It is a branch in time, not a branch in space. That is to say, a git branch means that code development diverged at some point in the past but the two branches have a common history at some point. A branch in space is, for example, a new folder containing a new project.

Branches don't really make much sense if branch A is completely different to branch B: you might as well have a whole new repository.

Sorry that's such a long answer. I hope it's helpful!

Cameron Skinner
  • 51,692
  • 2
  • 65
  • 86
  • thanks so much for your prompt and thorough response. I need some clarification. When I mkdir are you saying that I should create a subfolder in there called "Project A" and then proceed from there? Also, what does "cp -r /path/to/projectA ." do? – LuxuryMode Dec 12 '10 at 18:44
  • Yes, create one subfolder inside the repository for each project. The `cp` command copies the existing `projectA` folder to the current directory. You can replace those with `mkdir projectX` if the projects don't yet exist. I've assumed you're on Linux; in Windows you can probably just drag-and-drop the project folder into the repository. At the end of all this you have one repository in /path/to/repo, with two folders inside it (and a .git folder). – Cameron Skinner Dec 12 '10 at 20:04
  • thanks. to successfully push, i need to add, commit, then push, right? how do i add the entire project folder that i dragged-and-dropped into the repo? would i just do "git add project/"? Also, I keep getting "fatal: username/repo.git doesnt appear to be a git repo" when trying to push... – LuxuryMode Dec 13 '10 at 00:48
  • Make sure you clone the master repository (or use `git init`) first to avoid the "doesn't appear to be a git repo" problem. Add project; commit; push is correct. – Cameron Skinner Dec 13 '10 at 22:26
0

Let "android project in its own folder" be "A", "repo that I cloned" be "B". :)

First turn your project A into a git repository, if it isn't one. (git init)

Then you can just add it as a remote in B (git remote add ..., see help) and pull it into a branch local to B (git branch --help). Then you can push it to any of B's other remotes.

If you can provide pathnames, I can write up an example.

moeffju
  • 4,363
  • 2
  • 23
  • 22
  • 1
    @LuxuryMode Yes, I agree that branches are not the right model to use with disparate codebases. I would suggest putting both in separate repositories and working from that. – moeffju Dec 12 '10 at 18:59