Chan Kim
Chan Kim

Reputation: 6009

How to move local git repository to another machine and use it?

I sometimes use my local git repository to track changes I make before submitting it to our official project git repository.
I'm doing the same thing for a new project on a Ubuntu 16.04 machine now, but this time, because the working directory and my local repository is in the same hard disk (both in /dev/sdb1), if the hard disk fails, I won't be able to recover the data. This makes me feel uneasy, so I thought I should move the repository to another machine I own(It's Centos 6.9 machine) because I don't have another hard disk installed in the Ubuntu current machine.
So I tar'ed the ProjS.git directory (repository) from the Ubuntu machine, and ftp'd it to my CentOS machine and untar'ed it on /home2/repos.ProjS.git in the CentOS machine. And in the ubuntu machine's ~/testgit directory, I tried

ckim@chan-ubuntu:~/testgit$ git clone ssh://[email protected]/home2/repos/ProjS.git/
Cloning into 'ProjS'...
[email protected]'s password: 
fatal: protocol error: bad line length character: ----
ckim@chan-ubuntu:~/testgit$ fatal: The remote end hung up unexpectedly

The CentOS mahcine has never been used as a git repository for external machines. (But it had served as git repository for internal users, actually the same user me). In this case, what should I do? (maybe I should give access permission to myself.)

Upvotes: 1

Views: 425

Answers (1)

VonC
VonC

Reputation: 1329722

Instead of tar'ing the repository, I would use the git bundle command (as I described in "Fully backup a git repo?")

That will result in one file that you can copy over (scp for a copy over SSH), and clone.

 git clone myrepo.bundle

Once cloned, you can add the original repo SSH URL, but make sure to generate an SSH key, and register the public one to the original server.

ssh-keygen -t rsa -P""
# copy ~/.ssh/id_rsa.pub in 129.254.xxx.yyy:/home/ckim/.ssh/authorized_keys

That way, no password to ask.
Make sure the ~/.bashrc or ~/.profile in /home/ckin is silent (does not output strings)

Upvotes: 1

Related Questions