Reputation: 2728
I'm just starting to use Git, and I have a question:
When I create a new repository I get a folder in which I should put all the files (this folder contains .git
folder). Is this folder completely self-contained?
Let's say I've created a new repository and worked on the project for a while (doing commits). If I would take that folder and move it to another location (say another disk) would it still work? What if I move it to another computer? Could I have the repository/folder on an external device (external HDD or USB stick) and work with it on several computers?
Upvotes: 5
Views: 1079
Reputation: 143
Git folder may be sel contained but doesn't always act like it.
For example, today I struggled trying to copy a recovered .git folder and files to a new Virtual Box system after a hard drive corruption of repo stored on external usb drive inside Virtual Box/Lubuntu got disconnected accidentally before proper shutdown (fixed with chkdsk /f /x) .
As far as I could tell, all files seemed intact, and git log appeared normal except headings were in red. But all attempts to push to the newly created remote repo were met with various errors such as "cannot traverse parent" for various commit #'s and "are you sure you have permission?" Also, there were some messages about "symlinks" when files were originally copied from my recovered drive to the
newly created VM. Ithought it might be a permissions issue but all files were read/write all. Maybe .git has internal checks? End result I only succeeded in push to remote by deleting .git and initializing the local repo (basically a hard reset)...all history lost (was only a class project so was local only beforehand, now Bitbucket will prevent recurrence I hope.
But I thought .git folder was self contained.
Upvotes: 0
Reputation: 1326716
Almost.
push
or clone
or a bundle
), even though they are store within the .git
folder..git
directory), a hook working a local machine might not work on another one (because it is, for instance, a perl
script, and perl
isn't installed on the other machine).Git will recognized the moved repo as a git repo, so you can say it is self-contained in that regard.
I prefer moving my repo as a git bundle
(only one file to move).
But if you depend on any other (script/tools/other repos) for your repo to be complete and actually allowing you to work with it, you might need to consider moving other external elements as well.
Upvotes: 1
Reputation: 301327
The folder itself is self-contained.
Actually, if you have committed everything and don't have local changes, the .git
folder itself should be enough. The .git
folder is your repository. The rest of the contents of the folder is the checked out working directory. You may not copy those ( especially if there are lots of files ) to other machines.
Upvotes: 2
Reputation: 11611
Yes. That is the local repository, and it contains all the information about the repository.
The only thing that's not included is the global configuration.
See this free Git documentation for more details. Quoting from there:
Git creates the .git directory, which is where almost everything that Git stores and manipulates is located. If you want to back up or clone your repository, copying this single directory elsewhere gives you nearly everything you need.
Upvotes: 6
Reputation: 20180
Yes the folder is self contained, but you do need to have git installed if you want to do git operations on it from a different machine
Upvotes: 1
Reputation: 17858
Yes, it contains everything git needs.
And it does work with usb sticks.
Upvotes: 1