Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying a git repository to USB drive

Tags:

git

I am working on an Open Source project and I have a git repo on my machine with all the code. The repo is kind of big, and I would like to keep working on it while I do not have access to my computer.

If I copy the repo into my USB drive will it still be behaving as if I was on the original repo in my machine (same configurations, etc.)?

If copying does not work, is there a way of achieving this without having to recreate the repo from scratch on the USB drive?

like image 489
user1790813 Avatar asked Jun 27 '16 19:06

user1790813


People also ask

Can you copy and paste a git repository?

Technically speaking, git can operate just fine with copied repositories running around everywhere, because the whole point of a DCVS is that it doesn't have to know what's going on outside of any given repository, and in fact doesn't unless you tell it.

How do I download entire git repository?

When downloading materials to your laptop, it is easiest to download the entire repository. To do this, go to the GitHub page for the workshop, click on the green Code button, then download the repository as a ZIP file.

Can I use git on external hard drive?

Setup a git repository on an external hardrive and use this repository as the remote repository. On your laptop you can setup a local repository and push the changes to the remote repository. On external harddrive create a folder. Create a bare repo on the external harddrive.


3 Answers

It will work, but certain config variables won't travel with you.

Git has three levels of configuration: system-wide (all users on a PC), global (user-specific) and repo-specific.

The repo-specific configs will move around with your repo; the system and global configs won't. I would check your config files and if necessary also grab a copy of your user-specific configs.

like image 74
Doval Avatar answered Oct 16 '22 08:10

Doval


The best way is to add a remote (even though it's a local folder). In this way you can always transfer commits between the two. When you want to move

git init /mnt/usb/repo
git remote add usb /mnt/usb/repo
git push usb master

The last command can be used to push any branches into the folder as desired. If the local branch has no remote currently set as upstream you may have to do --set-upstream.

See also git how to add a local repo and treat it as a remote one on Stack Overflow.

like image 21
microbial Avatar answered Oct 16 '22 09:10

microbial


I kinda don't like the idea of copying git repositories from one place to another. Instead, I absolutely would recommend using a remote server for your code.

There's at least 2 excellent git as service around: the most famous is GitHub, which will freely host your code if you don't mind sharing it in a public repository. If you want to keep it private and don't want to pay for it, go for BitBucket.

like image 1
cristianoms Avatar answered Oct 16 '22 10:10

cristianoms