로컬 리포지토리를 추가하고 원격 리포지토리로 취급하는 방법


234

bak다음을 사용하여 로컬 리포지토리를 내 PC의 다른 로컬 리포지토리 이름으로 원격으로 만들려고합니다 .

git remote add /home/sas/dev/apps/smx/repo/bak/ontologybackend/.git bak

이 오류가 발생합니다.

fatal: '/home/sas/dev/apps/smx/repo/bak/ontologybackend/.git' is not a valid remote name

하나 bak는 다른 하나의 이름 을 가진 원격으로 구성된 다음 두 개의 로컬 저장소를 동기화하려고합니다 git pull bak.

가장 좋은 방법은 무엇입니까?


편집하다:

미안, 바보 나, 원격 추가가 다음과 같아야한다는 것을 깨달았다.

git remote add bak /home/sas/dev/apps/smx/repo/bak/ontologybackend/.git

리모컨의 이름은 주소 보다 먼저 갑니다 .

답변:


273

remote add명령 에 대한 당신의 주장은 반대입니다.

git remote add <NAME> <PATH>

그래서:

git remote add bak /home/sas/dev/apps/smx/repo/bak/ontologybackend/.git

자세한 내용 git remote --help은 참조하십시오.


6
는 IS .git말에 구체적으로하지만 필요?
— Erik Aigner

5
그것은 단지 길일뿐입니다 ... Git은 이름이 무엇인지 상관하지 않습니다.
— larsks

2
@ErikAigner 전통적으로 베어 repos는 ".git"접미사로 끝납니다. 일반적으로 자체 디렉토리는 아니지만 "/path/to/projectname.git"와 같습니다. -그 외에는 별 차이가 없습니다.
— Atli

7
나에게 분명하지 않은 절대 경로를 사용해야하는 것으로 보입니다. 상대 경로로 시도했을 때 fatal: '../dir' does not appear to be a git repository.
— Keith Layne

1
file://클라이언트 소프트웨어가 예상 프로토콜을 통해 경로에 액세스 할 수 있도록 경로의 맨 앞에 두고 로컬 저장소의 전체 경로를 사용해야합니다. 그리고 위의 Erik의 질문에 대한 답으로 .git길의 끝은 분명히 필요합니다.
— Scott Lahteine

158

쉬운 백업을 위해 저장소의 로컬 복사본을 유지하거나 외부 드라이브에 고정하거나 클라우드 저장소 (Dropbox 등)를 통해 공유하는 것이 베어 저장소 를 사용하는 것이 좋습니다 . 이를 통해 작업 디렉토리없이 저장소 사본을 작성하여 공유에 최적화 할 수 있습니다.

예를 들면 다음과 같습니다.

$ git init --bare ~/repos/myproject.git
$ cd /path/to/existing/repo
$ git remote add origin ~/repos/myproject.git
$ git push origin master

마찬가지로 원격 저장소 인 것처럼 복제 할 수 있습니다.

$ git clone ~/repos/myproject.git

9
이것은 "가장 좋은 방법은 무엇입니까?"라는 질문에 완벽하게 맞기 때문에 허용되는 답변이어야합니다. @opensas가 호출 한 "로컬 리포지토리로 처리 된 로컬 리포지토리"는 실제로 실제 디렉토리 (실제 원격 리포지토리와 동일)입니다.
— Jack '

1
나는 수정 제안 : 여부는 사용한다 "자식 remot 추가 기능을 .."+ "자식 푸시"또는 그냥 "자식 클론"여기에 표시됩니다 : stackoverflow.com/a/31590993/5446285 (아델 푸스 '답)
— 잭'

1
@ 잭-혼란스러운 점을 자세히 설명해 주시겠습니까? 나는 기꺼이 수정하지만 답변을 비교적 간결하게 유지하고 싶습니다.
— Matt Sanders

6

형식이 올바르지 않은 것 같습니다.

로컬로 생성 된 리포지토리를 공유하거나 다른 리포지토리의 기여를 원할 경우 새로운 리포지토리와 어떤 방식 으로든 상호 작용하려면 일반적으로 원격으로 추가하는 것이 가장 쉽습니다. git remote add [alias] [url]을 실행하면됩니다. 그러면 [alias]라는 로컬 원격 아래에 [url]이 추가됩니다.

#example
$ git remote
$ git remote add github git@github.com:schacon/hw.git
$ git remote -v

http://gitref.org/remotes/#remote


0

이 답변을 게시하여 로컬 리모컨이있는 로컬 리포지토리를 만드는 세 가지 시나리오를 설명하는 스크립트를 제공합니다. 전체 스크립트를 실행할 수 있으며 홈 폴더에 테스트 저장소가 만들어집니다 (windows git bash에서 테스트). 설명은 스크립트에 포함되어 있으므로 개인 메모에 쉽게 저장할 수 있습니다 (예 : Visual Studio Code).

나는 감사하는 것 또한 같은 잭 에 연결하기위한 이 대답 아델 푸스이 주제에 대한 설명에 좋은, 설명, 손이있다.

이것은 나의 첫 번째 게시물이므로 개선해야 할 사항을 알려주십시오.

## SETUP LOCAL GIT REPO WITH A LOCAL REMOTE
# the main elements:
# - remote repo must be initialized with --bare parameter
# - local repo must be initialized
# - local repo must have at least one commit that properly initializes a branch(root of the commit tree)
# - local repo needs to have a remote
# - local repo branch must have an upstream branch on the remote

{ # the brackets are optional, they allow to copy paste into terminal and run entire thing without interruptions, run without them to see which cmd outputs what

cd ~
rm -rf ~/test_git_local_repo/

## Option A - clean slate - you have nothing yet

mkdir -p ~/test_git_local_repo/option_a ; cd ~/test_git_local_repo/option_a
git init --bare local_remote.git # first setup the local remote
git clone local_remote.git local_repo # creates a local repo in dir local_repo
cd ~/test_git_local_repo/option_a/local_repo
git remote -v show origin # see that git clone has configured the tracking
touch README.md ; git add . ; git commit -m "initial commit on master" # properly init master
git push origin master # now have a fully functional setup, -u not needed, git clone does this for you

# check all is set-up correctly
git pull # check you can pull
git branch -avv # see local branches and their respective remote upstream branches with the initial commit
git remote -v show origin # see all branches are set to pull and push to remote
git log --oneline --graph --decorate --all # see all commits and branches tips point to the same commits for both local and remote

## Option B - you already have a local git repo and you want to connect it to a local remote

mkdir -p ~/test_git_local_repo/option_b ; cd ~/test_git_local_repo/option_b
git init --bare local_remote.git # first setup the local remote

# simulate a pre-existing git local repo you want to connect with the local remote
mkdir local_repo ; cd local_repo
git init # if not yet a git repo
touch README.md ; git add . ; git commit -m "initial commit on master" # properly init master
git checkout -b develop ; touch fileB ; git add . ; git commit -m "add fileB on develop" # create develop and fake change

# connect with local remote
cd ~/test_git_local_repo/option_b/local_repo
git remote add origin ~/test_git_local_repo/option_b/local_remote.git
git remote -v show origin # at this point you can see that there is no the tracking configured (unlike with git clone), so you need to push with -u
git push -u origin master # -u to set upstream
git push -u origin develop # -u to set upstream; need to run this for every other branch you already have in the project

# check all is set-up correctly
git pull # check you can pull
git branch -avv # see local branch(es) and its remote upstream with the initial commit
git remote -v show origin # see all remote branches are set to pull and push to remote
git log --oneline --graph --decorate --all # see all commits and branches tips point to the same commits for both local and remote

## Option C - you already have a directory with some files and you want it to be a git repo with a local remote

mkdir -p ~/test_git_local_repo/option_c ; cd ~/test_git_local_repo/option_c
git init --bare local_remote.git # first setup the local remote

# simulate a pre-existing directory with some files
mkdir local_repo ; cd local_repo ; touch README.md fileB

# make a pre-existing directory a git repo and connect it with local remote
cd ~/test_git_local_repo/option_c/local_repo
git init
git add . ; git commit -m "inital commit on master" # properly init master
git remote add origin ~/test_git_local_repo/option_c/local_remote.git
git remote -v show origin # see there is no the tracking configured (unlike with git clone), so you need to push with -u
git push -u origin master # -u to set upstream

# check all is set-up correctly
git pull # check you can pull
git branch -avv # see local branch and its remote upstream with the initial commit
git remote -v show origin # see all remote branches are set to pull and push to remote
git log --oneline --graph --decorate --all # see all commits and branches tips point to the same commits for both local and remote
}

당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.