I started using Git/SourceTree/Bitbucket lately. Can I move a local Git repository to elsewhere within my hard drive safely?
Because some of the large files are ignored by Git, I cannot really pull the repository from a remote repository to get the exact copy of all the files.
If I simply move or copy the home directory that contains .git to elsewhere, would it cause any mess to Git? If the absolute paths matters to Git, I guess it would, but I'm not sure.
No, moving or copying the .git/
folder will not cause problems for git; git is not connected to your repo in any way, and git doesn't care about absolute paths, only relative paths inside the project folder.
Git is just an executable on your machine. It can run anywhere, as long as it's in your path. I often drag my various .git/
folders to different places, or even onto my thumb drive (usually I drag the whole repository folder, but I've also just brought the .git/
folder by itself). The nice thing about git is that literally everything about your repo is in that folder. You don't even need to bring the working tree files with you. If you drop the .git/
folder - or a copy - into another folder, you can git checkout master
in that folder, and git will rebuild the working tree there.
This is the great thing about everything being data. Git is not attached to your repository at all. You just call git to do work on your repository to create or change the data that exists there, and then it lets go entirely again.
Keep in mind you can clone your own local repo:
$ git clone oldrepo newrepo
Git will copy the oldrepo
to the newrepo
(newrepo
can be a path to anywhere on your local filesystem), creating that folder in the process. Also, newrepo
will have a remote added automatically - origin
- that points back to oldrepo
, so you could do work in oldrepo
, and fetch it in over in the newrepo
folder. If you don't want that remote (it's harmless) you can just do git remote rm origin
in the new repo. If you want to hook the copied repo back up to a server online, just do git remote add origin <url>
. If you're not sure what the URL was, do a git remote -v
in the oldrepo
and copy the URL from there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With