Git clone 시에 다른 organization 이나 다른 team 의 repo 를 clone 할때 다음과 같은 에러가 발생하는 경우가 있다.

 $git clone https://github.com/otherTeam/test.git
Cloning into 'test'...
remote: Repository not found.
fatal: repository 'https://github.com/otherTeam/test.git' not found

이때 기존에 사용했던 계정이 다른 organization 에 소속이 안된경우가 있을수 있는데 다음 부분에 파일에 내용을 살펴본다.

$cat ~/.git-credentials
https://other%40test.com:testpassword@github.com/otherTeam/test.git

위의 내용을 보면 해당 repo 에 other@test.com 이라는 계정에 testpassword 라는 암호가 저장되어있는데, clone 을 받으려는 repo 에 other@test.com 이라는 계정이 권한이 없는경우 해당 라인을 삭제한다.

이후에 원하는 repo 의 clone 을 받으려고 다시 시도하면 계정과 비번을 입력받는 창이 뜨는데, 이때 입력을 하면 제대로 clone 이 받아지게 된다.

이때 저장한 계정 정보는 위의 .git-credentails 파일에 저장되게 된다.

Posted by leechwin
,

Git merge 를 수행하는경우 conflict 가 나는 경우가 있다. 이때는 일일이 Conflict 를 수정해도 되지만, 현재 branch 나 merge 대상인 branch 의 내용을 바로 적용하면 이런 conflict 를 일괄적으로 수행하게 할 수 있다.

# git merge -X<option> <branch>
# option = ours, theirs 등등

# ex)
# -Xtheris 로 실행하면 현재 branch 와 conflict 가 발생할경우 otherBranch 브랜치 내용으로 적용
$ git merge -Xtheris otherBranch

참고
https://git-scm.com/book/ko/v2/Git-%EB%8F%84%EA%B5%AC-%EA%B3%A0%EA%B8%89-Merge
https://git-scm.com/docs/merge-strategies

Posted by leechwin
,

gitlab 이나 github 등을 이용하면서 git branch, tag, commit history 등 git repository 자체를 export 해서 다른 repository 에 import 해야할 경우가 있다.

이때 gitlab 이나 github 등의 UI 에서 export 를 제공해주는 경우도 있지만, 그러지 못한 환경일 경우, git command 로 export 하는 방법을 알아본다.

Export

1. --mirror 옵션으로 git clone

git clone --mirror {git repository url}
# ex)
$ git clone --mirror https://github.com/leechwin/leechwin.github.com
   --mirror
       Set up a mirror of the source repository. This implies --bare. Compared to --bare,
       --mirror not only maps local branches of the source to local branches of the
       target, it maps all refs (including remote-tracking branches, notes etc.) and sets
       up a refspec configuration such that all these refs are overwritten by a git remote
       update in the target repository.

2. git clone 을 수행하면 xxx.git 폴더가 생기고 다음과 같은 내용이 들어있다.

xxx.git
.
├── branches
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   └── update.sample
├── info
│   └── exclude
├── objects
│   ├── info
│   └── pack
│       ├── pack-bf556429f20d728f5f1e40739c8e886b0ac1eca7.idx
│       └── pack-bf556429f20d728f5f1e40739c8e886b0ac1eca7.pack
├── packed-refs
└── refs
    ├── heads
    └── tags

3. 위의 xxx.git 폴더를 압축하여 필요한곳으로 파일로 전송할 수도 있다.

Import

1. export 된 파일의 압축을 풀고 해당 xxx.git 폴더안에서 다음명령을 통해 새로운 repository 로 연동할 수 있다.

# 폴더 안으로 이동
$ cd xxx.git

# 새로운 repository 설정
$ git remote set-url --push origin {new git repository url}
# ex)
$ git remote set-url --push origin https://github.com/leechwin/new.leechwin.github.com

# 새로운 repository 에 push
$ git push --mirror

다른 Git 간에 특정 branch 를 복사하고 싶을때

# 새로 이동될 git
$ git clone {git repository url}
$ cd xxx
# 복사할 대상 git 을 upstream 으로 설정
$ git remote add upstream {git repository url}
$ git fetch upstream

# 복사할 대상 git 의 branch 로 부터 branch 생성
# git checkout -b {생성할 branch 이름} {원격 저장소의 branch 이름}
$ git checkout -b test-branch upstream/test-branch
// 새로 추가된 branch를 upstream에서 내 repository의 remote를 따라가도록 설정
$ git branch -u origin/{생성할 branch 이름}
$ git push origin
Posted by leechwin
,

Git Push 시에 등록된 여러 Reviewer를 등록하는 방법에 대해 알아보자.


Git Config 파일을 수정하는 방법

  • Git Clone 이후에 {repo}/.git/config 파일에 receivepack 명령어를 넣는 방법
  • 방법
    • Git Clone
    • {repo}/.git/config 파일에 다음과 같이 수정
      • receivepack 명령어에 리뷰어들을 모두 넣어 등록
        • [remote "origin"]
          url = blabla...
          fetch = +refs/heads/*:refs/remotes/origin/*
          receivepack = git receive-pack --reviewer={email} --reviewer={email} --reviewer={email} 
    • 이후 git push 명령시에 자동으로 Gerrit reviewer 들이 등록된다.
  • 단점
    • 각 Git Repository 마다 config 설정을 해줘야 한다.
    • Git Repository를 통째로 삭제하고, Git Clone을 다시 받으면, config 파일도 삭제되기 때문에 위의 작업을 다시해야한다.


Bash Command로 등록하는 방법

  • Bash command로 "git-push" 라는 wrapper command를 작성하여 global 하게 reviewer를 등록하는 방법
  • 방법
    • bashrc 파일을 다음과 같이 수정
      • $ vi ~/.bashrc
      • function git-push() {
            git push --receive-pack='git receive-pack --reviewer {email} --reviewer {email}' origin HEAD:refs/for/$1
        }
    • 수정된 .bashrc 파일을 실행
      • $ source ~/.bashrc
    • 이후 어디에서나 다음과 같은 command를 사용 가능
      • $ git-push {branch}
      • $ git-push develop
      • $ git-push master
    • 위의 명령 실행시 자동으로 Gerrit reviewer 들이 등록된다.
  • 장점
    • 각 Git Repository 마다 config 설정이 필요없이 어느 Git Repository에서나 사용 가능
  • 단점
    • push 와 동시에 리뷰어가 자동 등록 되 커밋 별 선택적 리뷰어 등록이 불가능.
    • 경우에 따라 등록된 리뷰어를 다시 지울 필요가 있거나 version up 등 모든 리뷰어 등록이 필요 없는 경우 불편할 수 있다.


Posted by leechwin
,

[Git] 기본설정

Git 2016. 12. 21. 14:59

Git 사용시 기본 설정방법에 대해 알아본다.


Git 설정확인

  • $ git config --list


기본사용자설정

  • $ git config --global user.name "ChangHyun Lee"
  • $ git config --global user.email leechwin1@gmail.com


Commit Template 설정

  • $ git config --global commit.template {Template 파일 경로}
  • $ git config --global commit.template /home/leechwin/git/commit.template


Commit Template 해제

  • config --global --unset commit.template


색상 설정

  • $ git config --global color.ui true


CRLF 설정(커밋시 CRLF를 LF로 변환)

  • Linux
    • $ git config --global core.autocrlf input
  • Windows
    • $ git config --global core.autocrlf true

SSH Config 설정
  • ~/.ssh/config 파일 설정 예제
    • Host tizen
    • User leechwin
    • Port 29418
    • Hostname review.tizen.org
    • IdentityFile ~/.ssh/id_rsa
  • Proxy 환경일 경우 Proxy 설정 추가
    • ProxyCommand nc -x111.111.111.111:18080 -Xconnect review.tizen.org 29418

Change ID 자동설정 예제
  • $ cd gitDir
  • $ scp -p -P 29418 leechwin@review.tizen.org:hooks/commit-msg .git/hooks/
  • SSH Config 설정이 되어있다면
    • $ scp -p -P 29418 tizen:hooks/commit-msg .git/hooks/


설정된 속성은 다음 파일에 저장된다.

  • /etc/gitconfig : 시스템 전역 ( git config --system )
  • ~/.gitconfig : 특정 사용자 ( git config --global )
  • .git/config : 특정 Git


Posted by leechwin
,

Git 을 사용하여 개발 중, 여러 commit 들이 모여서 conflict가 나거나 여러가지 이유로 기존 commit 한 내용에 추가로 commit을 하려고 하면 다음과 같은 에러가 나는 경우가 있다.


fatal: You are in the middle of a cherry-pick -- cannot amend. 


이 상황에서는 git rebase, git commit --amend 등의 명령이 잘 동작하지 않는데 이를 해결하려면, 다음 명령을 수행하면 된다.

  • git commit --allow-empty

위의 명령을 실행 후 git rebase 혹은 git commit --amend 를 수행하면 기존 commit 한 내용에 이어서 추가 수정한 내용을 이어서 commit 할 수 있다.

Posted by leechwin
,

Git repository 가 외부에 있고 내부망에서 개발을 하는 회사등과 같은 개발환경에서 git 을 사용하다보면, 아래와 같은 에러가 발생하며 동작을 안하는 경우가 있다.


ssh_exchange_identification: read: Connection reset by peer

fatal: The remote end hung up unexpectedly 


Git 서버와의 연결이 끊겨서 사용이 불가능한 경우인데, 기존에 잘 사용하고 있었다가 발생한 문제라면 해결책은 너무도 간단하다.

네트웍 연결이 끊겼는지 확인하고, 문제가 없다면, 내부망일경우 프록시가 제대로 동작하는지 확인을 해보면 된다.

Posted by leechwin
,