移动时,计算机之间的git存储库同步? [英] git repository sync between computers, when moving around?

查看:66
本文介绍了移动时,计算机之间的git存储库同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有台式机和笔记本电脑,
,有时我在桌面上工作,有时我会在笔记本电脑上工作。



是一个来回移动git仓库的最简单方法吗?



我希望git仓库是相同的,
,这样我就可以继续离开在另一台计算机上。



我想确保在两台计算机上都有相同的分支和标签。



感谢
Johan



注意:我知道如何使用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

然后从其他计算机中的其中一台尝试使用克隆获取副本:



$ g $ clone $ user $ server git_test / workspace /
在/ home / user / git_test / repo1中初始化的空Git仓库/工作区/ .git /
警告:您似乎已经克隆了一个空的存储库。

然后进入该回购并添加一个文件:

  cd工作区/ 
echotest1> testfile1.txt
git add testfile1.txt
git commit testfile1.txt -m添加文件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

现在我们可以看到测试文件了。



现在我们可以编辑更多内容并重新更新服务器。

  echotest2>> testfile1.txt 
git add testfile1.txt
git commit -mTest2
git push origin master

然后我们回到第一个客户端,做一个git pull来查看更新的文件。
现在我可以在两台计算机之间来回移动,
,如果我愿意的话,也可以添加三分之一。

div>

我认为,有多种方法。我只会描述一下,我如何处理这个问题。



我有一个上网本作为24/7服务器,可以存放多个git-repository。从/到那里,我通过SSH推送和更改。从外部访问我使用dyndns.org。它工作正常,特别是因为我有两个以上的系统,需要访问一些存储库。



更新:一个小例子。
可以说我的上网本被称为上网本。我在那里创建一个仓库

  $ ssh username@netbook.local 
$ cd〜/ git
$ mkdir newThing
$ cd newThing
$ git init --bare

在我的我会创建一个桌面的克隆。也许我还会添加一些文件

  $ git clone username@netbook.local:/ home / username / git / newThing 
$ git add。
$ git commit -mInitial
$ git push origin master

在我的便携式计算机上,我将(首先)执行相同的操作,但对于远程访问(从我的局域网外部),我还将添加外部地址。

  $ git clone username@netbook.local:/ home / username / git / newThing 
$ git remote add externalName username@mydyndns.home-ip.org:/ home / username / git / newThing
$ git pull externalName master

它只是git(/ git工作流程)的工作方式。您可以根据需要添加任意数量的远程存储库。如果两个或两个以上涉及相同的物理存储库,则无关紧要。你不需要一个自己的本地服务器,你可以使用任何公共服务器,你有ssh访问。当然,如果你不需要从外部访问,你根本不需要公共服务器。裸仓库也可以位于桌面系统上,然后您可以在本地文件系统中创建工作副本仓库。

  $ mkdir myRepo; cd myRepo 
$ git init --bare
$ cd / path / to / myProject
$ git remote add origin / path / to / myRepo
$ git add。; git commit -mInitial; git push origin master

这就是我如何处理这个问题的方式,罚款(如果不是完美的;))



阅读内容: http://progit.org/
真的很好的书.-


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.

解决方案

I think, there are multiple approaches. I will just describe, how I handle this

I have one netbook as a 24/7 server, that holds multiple git-repositories. From/To there I push and pull changes via SSH. For access from outside I use dyndns.org. It works fine, especially because I have more than two systems, that needs access to some of the repositories.

Update: A little example. Lets say my netbook is called "netbook". I create a repository there

$ ssh username@netbook.local
$ cd ~/git
$ mkdir newThing
$ cd newThing
$ git init --bare

On my desktop I will than create a clone of it. Maybe I will add some files also

$ git clone username@netbook.local:/home/username/git/newThing
$ git add .
$ git commit -m "Initial"
$ git push origin master

On my portables I will (first) do the same, but for remote access (from outside my LAN), I will also add the external address.

$ git clone username@netbook.local:/home/username/git/newThing
$ git remote add externalName username@mydyndns.home-ip.org:/home/username/git/newThing
$ git pull externalName master

Its just the way git (/git workflows) works. You can add as many remote repositories as you like. It doesnt matters, if two or more refers to the same "physical" repositories. You dont need an own local "server", you can use any public server, to which you have ssh access. And of course you dont need a public server at all, if you dont need access from outside. The bare repository can also be on the desktop system and you can then create a working-copy-repository within the local filesystem.

$ mkdir myRepo; cd myRepo
$ git init --bare
$ cd /path/to/myProject
$ git remote add origin /path/to/myRepo
$ git add .; git commit -m "Initial"; git push origin master

This is the way, how I handle this, and I for me it works quite fine (if not perfect ;))

Something to read: http://progit.org/ Really good book.-

这篇关于移动时,计算机之间的git存储库同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆