5

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?

3 Answers 3

23

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 
Sign up to request clarification or add additional context in comments.

10 Comments

And I suppose I'd follow the instructions here to create a server by cloning a bare repository from that bundle: git-scm.com/book/en/v2/… right?
@BT yes, if you want to push to that repo, it is best it is a bare repo. (although that changed recently: stackoverflow.com/a/28261790/6309)
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) shop.oreilly.com/product/0636920024774.do
@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 ;)
The lecture is not for you, its for the asker
|
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

2 Comments

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.
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
0

Safest Option (exclude gitignored and uncommitted files):

git bundle create myreponame.bundle --all is safest, but it won't copy over ignored files in your .gitignore such as local config, IDE config, secrets, data, etc. It won't copy any uncommitted changes or files either.

Alternative Option (include gitignored and uncommitted files):

I recently migrated git repos from Windows to Linux (Ubuntu). This is the process I used to migrate dozens of git repositories which had lots of data, secrets, etc. that were ignored via .gitignore or recent code changes that weren't committed yet but I wanted to include in the migration anyways.

  1. Directly copy the entire Git Repo from Windows to Linux

    • Make sure to copy the entire git repo including the .git folder
    • At this point, when I ran git status on Linx, none of the files in the repo were being tracked
  2. Run find . -type f -print0 | xargs -0 dos2unix on the repo in Linux.

    • This will convert all the line endings from Windows format (CRLF) to Linux format (LF).
    • Make sure to include the .git folder when you run this command
  3. Run git add .

    • This will allow git to track all files again. Usually, the repo is bugged and will show all files as being untracked when you first copy it to Linux.
  4. Run git restore --staged .

    • This is the final step. It will restore the git repo to the exact status you left it in on Windows. When you do git add in the step above, it adds every file that's not ignored in .gitignore. However, that means that some uncommitted files or uncommitted changes will also be added. By running git restore, you untrack these changes and bring the repo back to it's original state.

That's all you need to do to migrate a git repo from Windows to Linux!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.