假设我有一台台式电脑和一台笔记本电脑,有时我在台式机上工作,有时我在笔记本电脑上工作。
来回移动git存储库的最简单方法是什么?
我希望git存储库是相同的,这样我就可以在另一台计算机上我离开的地方继续。
我想确保两台计算机上都具有相同的分支和标签。
谢谢约翰
注意:我知道如何使用SubVersion做到这一点,但是我对git如何工作感到好奇。如果更简单,我可以将第三台pc用作经典服务器,两台pc可以同步。
注意:两台计算机都在运行Linux。
更新:
因此,让我们尝试XANI的想法:在服务器上使用裸露的git repo,并使用KingCrunch的push命令语法。在此示例中,有两个客户端和一个服务器。
因此,让我们首先创建服务器部分。
ssh user@server
mkdir -p ~/git_test/workspace
cd ~/git_test/workspace
git --bare init
因此,然后我尝试从其他计算机之一获取带有克隆的回购副本:
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.
然后进入该仓库并添加一个文件:
cd workspace/
echo "test1" > testfile1.txt
git add testfile1.txt
git commit testfile1.txt -m "Added file testfile1.txt"
git push origin master
现在,服务器已使用testfile1.txt更新。
无论如何,让我们看看是否可以从另一台计算机上获取此文件。
mkdir -p ~/git_test/repo2
cd ~/git_test/repo2
git clone user@server:~/git_test/workspace/
cd workspace/
git pull
现在我们可以看到测试文件了。
此时,我们可以使用更多内容对其进行编辑,然后再次更新服务器。
echo "test2" >> testfile1.txt
git add testfile1.txt
git commit -m "Test2"
git push origin master
然后,我们回到第一个客户端并进行git pull查看更新的文件。现在,我可以在两台计算机之间来回移动,如果愿意,可以添加第三台计算机。