<이전글>

2020/12/03 - [IT/Git] - [Git] Git 원격 저장소 여러개 연결

 

[Git] Git 원격 저장소 여러개 연결

한 프로젝트를 깃랩과 깃허브 두 곳에 push하고 싶어서 알아봤다. 현재 로컬 저장소인 Mini_WAS 폴더와 깃랩 원격 저장소와 연결되어있다. 이제 내 깃허브 원격 저장소와도 연결하고 싶어서 과정을

song-yujin.tistory.com

 

1. git 연결 끊기


git 연결 끊기
git remote remove origin

 

git init 취소
rm -r .git

 

 현재 연결되어있는 저장소 경로 보기
git remote -v

 

 

2. 새로운 로컬 저장소 연결

깃랩에 있는 Mini_WAS 저장소와 새롭게 연결하고 싶은 로컬 저장소를 연결하려고 한다.

 

새로 연결하고 싶은 원격 저장소명과 URL 
git remote add "저장소명" "url"

 

그런데!!

이전 글을 참고해서 git push origin master과 git push origin +master 둘 다 해봤는데 아래처럼 표시가 되었다.

$ git push origin master
To http://~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'http://gitlab-intern.polloud.com/songij4/mini_was.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

~~~~@~~~ MINGW64 ~/eclipse-workspace/Mini_WAS2 (master)
$ git push origin +master
Enumerating objects: 87, done.
Counting objects: 100% (87/87), done.
Delta compression using up to 4 threads
Compressing objects: 100% (77/77), done.
Writing objects: 100% (87/87), 38.01 KiB | 2.38 MiB/s, done.
Total 87 (delta 12), reused 0 (delta 0), pack-reused 0
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To http://gitlab-intern.polloud.com/songij4/mini_was.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'http://gitlab-intern.polloud.com/songij4/mini_was.git'

 

원인

 

깃랩은 저장소를 생성하면 기본설정이 '관리자(Maintainers)'만 수정 가능하다.

'개발자(Developers)'는 푸시 허용이 돼 있지 않아서 나는 오류이다.

 

 

해결 방법

 

깃랩 레파지토리에서 > settings > Repository > Protected Branches > 선택하는 부분에 Developers + Maintainers 해주면 된다. 

그리고 다시 git push origin +master 해주면 잘 된다!

'IT > Git' 카테고리의 다른 글

[Git] Git 원격 저장소 여러개 연결  (0) 2020.12.03
[Git]git branch 실습  (0) 2020.11.16

한 프로젝트를 깃랩과 깃허브 두 곳에 push하고 싶어서 알아봤다.

 

현재 로컬 저장소인 Mini_WAS 폴더깃랩 원격 저장소와 연결되어있다. 

이제 내 깃허브 원격 저장소와도 연결하고 싶어서 과정을 기록하려고 한다.

 

새로 연결하고 싶은 원격 저장소명과 URL 
git remote add "저장소명" "url"

 

원격 저장소 목록 확인
git remote -v

 

 

origin(깃랩)으로 push와 저장소명(깃허브)으로 push
git push origin master 
git push 저장소명 master
//ex) git push Mini_WAS master

 

origin(깃랩)으로 pull와 저장소명(깃허브)으로 pull
git pull origin master
git pull 저장소명 master

 

 

그런데!

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'http://gitlab-intern.polloud.com/songij4/mini_was.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

push 하려고 하니까 이런식으로 에러가 떴다.

git pull을 해줬는데도 안됐다. 그래서 구글링 해봤다.

 

 

원인

 

원인은 .gitignore 파일 또는 README.md 파일로 인해 발생한다고 한다.

 

해결 방법

 

master 앞에 +를 붙이기
git push origin +master

 

 

 

'IT > Git' 카테고리의 다른 글

[Git] git 연결 끊기 & 새로운 로컬 저장소 연결  (0) 2020.12.14
[Git]git branch 실습  (0) 2020.11.16

Git(버전관리시스템)


  • git의 목적 
  1. 버전관리
  2. 백업
  3. 협업
  • branch

- 필요에 의해서 작업이 분기되는 현상 

예) 개발 진행 중 현재 작업했던 내용을 서버에 반영하기 위해서 여러가지 테스트를 진행하면서 문제점은 없는지 체크하기 위함. main이 되는 작업과 test를 위한 작업을 분기.

 

 

 

 

branch 만들기


1. 브랜치 목록을 볼 때 

git branch

 

2. 브랜치 생성할 때

git branch "새로운 브랜치 이름"

 

3. 브랜치 삭제할 때 

git branch -d

 

4. 병합하지 않은 브랜치를 강제 삭제할 때

git branch -D

 

5. 브랜치를 전환(체크아웃)할 때

git checkout "전환하려는 브랜치 이름"

 

6. 브랜치를 생성하고 전환까지 할 때

git checkout -b "생성하고 전환할 브랜치 이름"

 

 

 

 

branch 정보 확인


1. 브랜치 간에 비교할 때

git log "비교할 브랜치 명 1".."비교할 브랜치 명 2"

 

2. 브랜치 간의 코드를 비교할 때

git diff "비교할 브랜치 명 1".."비교할 브랜치 명 2"

 

3. 로그에 모든 브랜치를 표시하고, 그래프로 표현하고, 브랜치 명을 표시하고, 한줄로 표시할 때 

git log --branches --graph --decorate --oneline

 

 

 

 

branch 병합


1. A 브랜치로 B 브랜치를 병합할 때 (A ← B)

git checkout A
git merge B

 

2. 충돌이 일어났을 때

 

- 충돌이 생기면 "Auto-merging ..." 메시지가 뜸

- git status를 하면 충돌이 일어난 파일 찾을 수 있음

- 충돌 작업을 끝냈다는 것을 git에게 알려줌

git add 'conflicted file name'

 

 

 

 

stash 


stash : 감추다, 숨겨두다의 뜻을 가지고 있음

 

"다른 브랜치로 checkout을 해야 하는데 아직 현재 브랜치에서 작업이 끝나지 않은 경우는 커밋을 하기가 애매합니다. 
이런 경우 stash를 이용하면 작업중이던 파일을 임시로 저장해두고 현재 브랜치의 상태를 마지막 커밋의 상태로 초기화 할 수 있습니다.  그 후에 다른 브랜치로 이동하고 작업을 끝낸 후에 작업 중이던 브랜치로 복귀한 후에 이전에 작업하던 내용을 복원할 수 있습니다. "

 

 

1. 하던 작업을 저장하고 가장 최근 commit 상태로 만듦

git stash

 

2. 저장되어 있는 작업 중 가장 최근 stash를 가져옴

git stash apply

git stash pop   //git stash apply + git stash drop 

pop은 한번 불러오면 stash 목록에 저장한 시점이 삭제되어있고 apply는 해당 stash를 불러와도 list에 남아있음

 

 

3. stash 목록볼 때

git stash list

 

 

4. stash 삭제할 때

git stash drop[stash@[숫자]]

 

4. stash help

git stash --help

 

# git stash는 명시적으로 삭제하지 않는다면 항상 살아있다.

# git stash는 최소한 버전관리가 되는 파일만 적용된다.

 

<참고>

opentutorials.org/course/2708

'IT > Git' 카테고리의 다른 글

[Git] git 연결 끊기 & 새로운 로컬 저장소 연결  (0) 2020.12.14
[Git] Git 원격 저장소 여러개 연결  (0) 2020.12.03

+ Recent posts