4

I have a git server running on a windows desktop machine that has inexplicably lost the ability to connect to the internet. I want to move the repo to a linux machine. I already know how to switch my cloned repos to point to the new master once it's setup, but I need to get it to a new machine first.

I assume since windows and linux are a bit different, I can't just copy the repo directory verbatim. But maybe I can? What are my options?

B T
  • 57,525
  • 34
  • 189
  • 207

2 Answers2

21

You can do a git bundle: it will compress the repo in one file. It is easy to move one file, as opposed to a all repo with all its files.

git bundle create /tmp/myrepo.bundle --all

See "How can I email someone a git repository?"

Once copied on Linux, you can clone from that one file.

git clone myrepo.bundle
cd myrepo
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • And I suppose I'd follow the instructions here to create a server by cloning a bare repository from that bundle: http://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server right? – B T Feb 15 '15 at 01:19
  • @BT yes, if you want to push to that repo, it is best it is a bare repo. (although that changed recently: http://stackoverflow.com/a/28261790/6309) – VonC Feb 15 '15 at 01:24
  • Bundle is a limited solution since it will create a"read only" repo. he will not be able to actually work on i just to read it content – CodeWizard Feb 15 '15 at 01:26
  • @jsexpert he can clone it and make a fully functional bare repo, which can be pushed to. The bundle is just for the transfer, no worries. – VonC Feb 15 '15 at 01:26
  • Why not simply copy the root folder to unix? its much more simple – CodeWizard Feb 15 '15 at 01:28
  • 1
    Im using a bundle for a while and its an excellent git feature. if you want to learn about it in depth you can view this video (you will have to purchase the series) http://shop.oreilly.com/product/0636920024774.do – CodeWizard Feb 15 '15 at 01:31
  • 1
    @jsexpert copying one file is more secure in term of repo integrity. As for git, I know quite a bit about it, no need for another book ;) – VonC Feb 15 '15 at 01:34
  • 1
    The lecture is not for you, its for the asker – CodeWizard Feb 15 '15 at 01:35
  • It doesn't seem to include the changes that were not committed, do we have to add any other flag to include uncommitted changes? – Kaushik R Bangera May 27 '22 at 02:31
  • @KaushikRBangera as far as I know, you need to add and commit first, before doing a bundle. – VonC May 27 '22 at 02:33
7

As suggested before you can create bundle. but bundle is a read-only repo.

It's the most simple thing to do: simply copy the root folder of your project (it must include the .git inside). Copy it to your USB and then to your Linux machine.

The only thing you will have to worry about is CRLF. which is the way git handles line feed.

On windows, it should have the value of true while on Linux it should have the value of the input as shown below

# Linux based OS should be: 
git config --global core.autocrlf input 

# Windows configuration
git config --global core.autocrlf true

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 3
    Without setting `autocrlf=input` every file shows as modified. I thought `find . -name "*" | xargs dos2unix` would be enough. Afterwards they all still show as modified, but with no differences from `git diff`. – Kevin Apr 26 '18 at 15:47
  • copying the root project folder like this doesn't work: `windows -> usb drive -> ubuntu`. I am not able to run it on Ubuntu afterwards. `git status` shows `fatal: cannot chdir to 'C:/Users/.../my_project': No such file or directory` – sunwarr10r Jan 13 '21 at 16:45