git repository sync between computers, when moving around?

Posted by Johan on Stack Overflow See other posts from Stack Overflow or by Johan
Published on 2011-02-09T17:18:05Z Indexed on 2011/02/14 7:25 UTC
Read the original article Hit count: 177

Filed under:
|

Hi

Let's say that I have a desktop pc and a laptop, and sometimes I work on the desktop and sometimes I work on the laptop.

What is the easiest way to move a git repository back and forth?

I want the git repositories to be identical, so that I can continue where I left of at the other computer.

I would like to make sure that I have the same branches and tags on both of the computers.

Thanks Johan

Note: I know how to do this with SubVersion, but I'm curious on how this would work with git. If it is easier, I can use a third pc as classical server that the two pc:s can sync against.

Note: Both computers are running Linux.


Update:

So let's try XANI:s idea with a bare git repo on a server, and the push command syntax from KingCrunch. In this example there is two clients and one server.

So let's create the server part first.

ssh user@server
mkdir -p ~/git_test/workspace
cd ~/git_test/workspace
git --bare init

So then from one of the other computers I try to get a copy of the repo with clone:

git clone user@server:~/git_test/workspace/
Initialized empty Git repository in /home/user/git_test/repo1/workspace/.git/
warning: You appear to have cloned an empty repository.

Then go into that repo and add a file:

cd workspace/
echo "test1" > testfile1.txt
git add testfile1.txt
git commit testfile1.txt -m "Added file testfile1.txt"
git push origin master

Now the server is updated with testfile1.txt.

Anyway, let's see if we can get this file from the other computer.

mkdir -p ~/git_test/repo2
cd ~/git_test/repo2
git clone user@server:~/git_test/workspace/
cd workspace/
git pull

And now we can see the testfile.

At this point we can edit it with some more content and update the server again.

echo "test2" >> testfile1.txt
git add testfile1.txt
git commit -m "Test2"
git push origin master

Then we go back to the first client and do a git pull to see the updated file. And now I can move back and forth between the two computers, and add a third if I like to.

© Stack Overflow or respective owner

Related posts about git

Related posts about version-control