0

Say I have this type of structure:

Project/Code files: C:\myCode

Git Repository: C:\Users\User1\MyGitRepoDir

How do I get my myCode code directory into MyGitRepoDir so that I can commit files, etc?

2 Answers2

2

Three options that I can think of:

  1. Copy paste the code from myCode into MyGitRepoDir

  2. Create a new git repo in myCode with git init

  3. Move the working dir of MyGitRepoDir. Probably don't want to do this if you don't know what you are doing.

Would need more details to provide a recommendation. Is there already code in MyGitRepoDir? Do they need to be in the same repo? Does each folder need to stay in their respective directories?

Community
  • 1
  • 1
Andy
  • 44,610
  • 13
  • 70
  • 69
  • I'm interested in option #2. I am using GitHub. Is there any way for me to create a new git repo in myCode dir and map that to my GitHub repo that already exists? –  Feb 17 '12 at 20:03
  • @shark Is there already code in your github repo? Do you want to keep that code? Is it the same/similar codebase? – Andy Feb 17 '12 at 20:05
  • There's actually no code in the github repo yet. I created the repo (I'm new to the git world) not thinking about the existing code. And now they are two separate directories. GitBash definitely doesn't seem like it wants to get out of my user directory, though. I'm probably just doing that wrong, too. –  Feb 17 '12 at 20:07
  • If there is no code in your github repo, you can just create a new repo in myCode with `git init`. Then push that repo up to github. Github gives you step by step to do this when you create the repo. – Andy Feb 17 '12 at 20:13
  • But then I'll have two repos in GitHub, right? The old one (empty), and the new one in myCode...? –  Feb 17 '12 at 20:14
  • You can push it to the empty one, or delete the empty one and push it to a new one. Your call on that one. – Andy Feb 17 '12 at 20:16
  • Andy, ok will do. Question for you, how do I change directories in GitBash??? GitBash opens up to my user dir (C:\Users\Me). My code is in (C:\myCode). But I can't seem to get away from C:\Users\Me to get to my code directory. –  Feb 17 '12 at 20:40
  • If you are using msysgit `cd /c/myCode/` – Andy Feb 17 '12 at 21:13
2

The code must be under the GIT repository root directory for it to be placed under source control. You would have to move/copy the directory. If you really want to have a repo at C:\myCode and then reference it in C:\Users\User1\MyGitRepoDir you would have to use submodules which can be quite painful, but if your application requires it, the complexity is justified. Hope this helps!

macduff
  • 4,655
  • 18
  • 29