Programing

이동할 때 컴퓨터 간 git 저장소 동기화?

lottogame 2020. 10. 13. 07:18
반응형

이동할 때 컴퓨터 간 git 저장소 동기화?


제가 데스크톱 PC와 노트북을 가지고 있고 때로는 데스크톱에서 작업하고 때로는 노트북에서 작업한다고 가정 해 보겠습니다.

git 저장소를 앞뒤로 이동하는 가장 쉬운 방법은 무엇입니까?

git 리포지토리가 동일하기를 원하므로 다른 컴퓨터에서하던 작업을 계속할 수 있습니다.

두 컴퓨터에 동일한 분기와 태그가 있는지 확인하고 싶습니다.

고마워요 요한

참고 : SubVersion으로이 작업을 수행하는 방법을 알고 있지만 이것이 git에서 어떻게 작동하는지 궁금합니다. 더 쉬우면 세 번째 PC를 두 개의 PC가 동기화 할 수있는 클래식 서버로 사용할 수 있습니다.

참고 : 두 컴퓨터 모두 Linux를 실행합니다.


업데이트 :

이제 서버의 베어 git 리포지토리와 KingCrunch의 push 명령 구문을 사용하여 XANI :의 아이디어를 시도해 보겠습니다. 이 예에는 두 개의 클라이언트와 하나의 서버가 있습니다.

그럼 먼저 서버 부분을 만들어 보겠습니다.

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을 수행합니다. 이제 두 컴퓨터 사이를 오가며 원하는 경우 세 번째 컴퓨터를 추가 할 수 있습니다.


여러 가지 접근 방식이 있다고 생각합니다. 어떻게 처리하는지 설명하겠습니다.

여러 git-repositories를 보유하는 24/7 서버로 하나의 넷북이 있습니다. 거기에서 나는 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 -m "Initial"
$ git push origin master

내 노트북에서도 동일한 작업을 수행하지만 LAN 외부에서 원격 액세스하려면 외부 주소도 추가합니다.

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


I would clone the repo from one box to the other, and then set up the two repos so that I can just git fetch from the other box.

Renaming the remote from origin to the name of the other box makes the remote branches easier to read.

Note that by just using git fetch (and not git push), this works well with non-bare repositories:

[user@foo repo]$ git fetch -v bar

[user@bar repo]$ git fetch -v foo

Easiest way: central repo created with --bare (so no checked out files, only .git stuff), or github

"Distributed" will look like that:

Setup:

  1. On laptop: git remote add desktop ssh://user@desktop/home/user/repo/path
  2. On desktop: git remote add laptop ssh://user@laptop/home/user/repo/path

Syncing:

git pull laptop/desktop (push won't work very well on non-bare repos because git won't modify checked out files when pushing to remote repo)

Or, make repo on pendrive ;)


How about simply using rsync?


Couldn't you just create a remote repository on GitHub, BitBucket or GitLab? (The latter two companies offer unlimited free private repositories). When you finish the day at work, simply use git push to push your changes to the remote repo. When you get home, just do git pull to pull your changes from work onto your home machine. Likewise, when you finish at home, do git push and then when you return to work, do git pull.


Well, you can push and pull (via Git) to the server you could potentially set up. Or you could store your repos at GitHub and use that as a syncing bridge.


You could make the repository on any of your computers, probably the desktop one and push/pull to it from both laptop and itself.

참고URL : https://stackoverflow.com/questions/4948190/git-repository-sync-between-computers-when-moving-around

반응형