꼬반 Blog

Git 활용하기

…or create a new repository on the command line

echo "# message" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/username/repo_addr.git
git push -u origin master

…or push an existing repository from the command line

git remote add origin https://github.com/username/repo_addr.git
git push -u origin master

…or import code from another repository

You can initialize this repository with code from a Subversion, Mercurial, or TFS project.


====== Git 활용하기 ======

가입하고 매달 $7 씩 내고 있는 (ㅠㅠ) git을 이제부터라도 잘 사용하기 위해 개발 중인 satm 소스를 git으로 관리하기로 했다.

구성은 아래와 같다.
개발머신 : VM Ubuntu
호스트 : 개인 PC
유저 : 실습생

유저가 내 개인 PC의 아이피로 VM에서 구동한 nodejs 에 접속하여 작업 하는데 이는 매우 불편하다.
일단 VM을 외부에서 접속할 수 있도록 VMware에 NAT 설정 등을 해야 했고 해당 VM을 계속 켜두어야 하고
서비스를 겸하다보니 자유롭게 개발에 어려움이 왔다. 그래서 git에 개발 소스를 commit 하고
서비스할 VM에서 해당 소스를 petch 하여 서비스하기로 결정. 이 서비스VM은 회사 vSpere 에 생성하여
바로 접근이 가능하도록 한다.

아래와 같은 방법으로 git에 소스를 commit 하였다.

1. git 저장소 생성하기
  cd /src folder // 해당 프로젝트 디렉토리로 이동
  git init // git 저장소를 생성한다.
2. git 저장소에 기존 소스 commit 하기
  // 먼저 기존 저장소의 branch 를 초기화 해주어야 정상적으로 동작 된다.
  git commit -m 'Initail Commit' --allow-empty
  git add . // 이러면 기존 폴더에 존재하는 소스들이 git에 쓸 준비가 됨.
  git commit -m 'comment' // 로컬 git에 commit 된다.
 
  // 중요한 것은 --allow-empty 로 한번 커밋 해주는 것
  // 그리고 앞으로도 변경되는 파일은 add 명령어를 통해 스테이지에 기록하여 줄 것
  // 그후 커밋
3. 외부 저장소에 push 하기
  // 외부 저장소를 git에 등록해준다.
  git remote add origin <주소>
  git push origin master
 
  // 정상적으로 잘 설정하였다면 외부 저장소에 push가 된다.
  // 추가 사항. 존재하던 파일을 삭제하는 경우. 스테이지에는 남아있기 때문에 rm 명령어로 삭제해줘야 한다.
  git rm -r <디렉토리>
  git commit -m 'comment' // 로컬 git에 commit 된다.

4. 외부 저장소 pull, merge 하기
http://git-scm.com/book/ko/v1/Git-%EB%B8%8C%EB%9E%9C%EC%B9%98-%EB%A6%AC%EB%AA%A8%ED%8A%B8-%EB%B8%8C%EB%9E%9C%EC%B9%98
http://git-scm.com/book/ko/v1/Git-%EB%B8%8C%EB%9E%9C%EC%B9%98-%EB%B8%8C%EB%9E%9C%EC%B9%98%EC%99%80-Merge%EC%9D%98-%EA%B8%B0%EC%B4%88

fatal 에러발생 시 참조 : http://stackoverflow.com/questions/25087532/git-fatal-bad-default-revision-head-with-all-new-repos

참조 : http://www.slideshare.net/einsub/svn-git-17386752
참조 : http://blog.beany.co.kr/archives/2927
참조 : http://rogerdudler.github.io/git-guide/index.ko.html

반응형

Article By 꼬반

*certificate* : VCP 5(2012), RHCSA 7 (2014), RHCE 7 (2015), RHCSA in REDHAT OpenStack(2017) *development language* : Javascript, NodeJS, Golang, html5, css3, shell script *middle ware* : NGINX, Apache, Tomcat, Docker, Docker Swarm, Mesos, Kubernetes, HCI,

Discuss about post