1

By default, I typically run git init and have the local repository in the root directory. I store and work with my project files on a small-ish SSD but have a BIG ol' SATA HD on the same machine not doing much. I was thinking I should get into the practice of using it for the actual repositories for each project.


EDIT:
By this I mean I have the directory structure:

SMALL-DRIVE > My Project > .git > repository files...
SMALL-DRIVE > My Project > src > dev files...

and while I'd like the keep the 2nd one as is, I want to move the 1st one to

BIG-DRIVE > repositories > My Project > .git > repository files... (or something similar)

Everything is staying on the same machine and there would be no change to the remote repository that I push to.

I believe I can pass git init this new path for new projects (pretty sure I can figure that out on my own), but is there a way to update an existing config to use the new path? And if so, is there a command that will move the current files in the repository or would I just manually move the .git directory?

Daveh0
  • 952
  • 9
  • 33
  • 1
    I don't think I worded my initial question clearly. i basically want to store the local repository files in a different directory (on a different drive... to take advantage of the extra space) than the project's root directory. See **EDIT** in original question. – Daveh0 Jan 15 '19 at 15:45

3 Answers3

2

Yes, you can.

Option 1 (Preferred): Mirroring

Just run these commands to mirror a repository:

git clone --mirror git@example.com/upstream-repository.git
cd upstream-repository.git
git push --mirror git@example.com/new-location.git

See more about mirroring here

Option 2: Manual clone & push

First step is to git clone the repository to a local directory.

Then, you add a new remote repository using git remote add <name> <url>

Then, you can simply git push <name> --all to send everything there

Daniel Trugman
  • 8,186
  • 20
  • 41
  • That's a good trick to know, but cloning will not retain everything (reflog, stashes, etc.). – jub0bs Jan 15 '19 at 14:54
  • @jubobs, stashes are local entities, so I don't think we should consider them as part of the clone. About reflogs, I actually don't know... That's a good question. – Daniel Trugman Jan 15 '19 at 15:05
  • If I understand the question correctly, I don't think the OP wants to leave anything behind; if so, stashes should not get lost. – jub0bs Jan 15 '19 at 15:07
  • @jubobs, I don't think the OP pushed his stashes to the remote repository, so there is no need in copying them. If you want to get a sense of what you need to do to push a stash, see this https://stackoverflow.com/questions/1550378/is-it-possible-to-push-a-git-stash-to-a-remote-repository – Daniel Trugman Jan 15 '19 at 15:35
  • I don't think the OP wants to push or clone his/her original repo. – jub0bs Jan 15 '19 at 17:42
2

[...] is there a way to update an existing config to use the new path?

If I understand your question correctly, you currently have a repo on a small but fast HD, and you'd like to

  • move the repo's .git directory to a big & slow HD,
  • yet keep the repo's working tree on the small & fast HD.

Am I right?

In that case, git init --separate-git-dir is right up your alley. Quoting git init's man page:

--separate-git-dir=<git dir> Instead of initializing the repository as a directory to either $GIT_DIR or ./.git/, create a text file there containing the path to the actual repository. This file acts as filesystem-agnostic Git symbolic link to the repository.

If this is reinitialization, the repository will be moved to the specified path.

So, simply cd to your repo, and then run

git init --separate-git-dir <desired-location-on-big-and-slow-drive>

I believe I can pass git init this new path for new projects [...]

Correct. Use the same command as above.

Community
  • 1
  • 1
jub0bs
  • 60,866
  • 25
  • 183
  • 186
  • 1
    @juobs - regarding the last section of your answer, everything **is** on the small/fast drive. I want to keep doing my development there but store the repository files on the big/slow-ish drive. – Daveh0 Jan 15 '19 at 15:56
  • @Daveh0 Ah yes. I misunderstood your question. Let me amend my answer... – jub0bs Jan 15 '19 at 17:12
  • 1
    @jubos - yup, that's exactly what I'm going for. Thanks!! I'll give `separate-git-dir `a try in a bit. – Daveh0 Jan 15 '19 at 19:29
  • 1
    @jubobs, GJ on understanding exactly what the OP wanted! I don't know about him, but you got my upvote :) – Daniel Trugman Jan 16 '19 at 08:55
0

Add a New Remote git to your Git Repo

git remote add origin git@yourgit.repo

Verify new remote repo

git remote -v

Community
  • 1
  • 1