Dev/Git

Git 간단한 사용법 - Init

Itips 2019. 6. 19. 21:02
반응형

Git 은 간단하고 유용하고 깔끔하고 그 사용법도 인터넷에 넘쳐 나지만 처음 사용자들에게는 그 개념을 이해하기가 생각처럼 쉽지않을 수도 있다. 그래서 일단 해보자.

 

1. Git 을 실험할 디렉토리 생성

[itips@itips ~] $ mkdir there
[itips@itips ~] $ cd there

 

2. Git repository 초기화

[itips@itips ~] $ git init --bare
Initialized empty Git repository in /home/itips/there/
[itips@itips ~] $ ls -al
total 40
drwxrwxr-x. 7 itips itips 4096 Jun 19 23:06 .
drwx------. 4 itips itips 4096 Jun 19 23:06 ..
drwxrwxr-x. 2 itips itips 4096 Jun 19 23:06 branches
-rw-rw-r--. 1 itips itips   66 Jun 19 23:06 config
-rw-rw-r--. 1 itips itips   73 Jun 19 23:06 description
-rw-rw-r--. 1 itips itips   23 Jun 19 23:06 HEAD
drwxrwxr-x. 2 itips itips 4096 Jun 19 23:06 hooks
drwxrwxr-x. 2 itips itips 4096 Jun 19 23:06 info
drwxrwxr-x. 4 itips itips 4096 Jun 19 23:06 objects
drwxrwxr-x. 4 itips itips 4096 Jun 19 23:06 refs

* git remote origin master 로 사용할 repository 가 완성되었다.

 

아래는 command console 에서 git 사용시 유용한 bash 설정이다. 

3. ~/.bashrc 파일에 아래와 같이 코드 삽입

[itips@itips ~] $ vi ~/.bashrc
# User specific aliases and functions
function git_branch {
        ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
        echo "("${ref#refs/heads/}") ";
}
PS1="[\[\033[1;32m\]\w\[\033[0m] \033[1;36m\]\$(git_branch)\[\033[0m\]$ "

 

4. 저장하고 나와서 source 명령으로 ~/.bashrc 를 실행하면 Command 프롬프트가 현재 checkout 중인 브렌치명을 보여준다.

[itips@itips ~] $ source ~/.bashrc
[~/there] (master) $ 

 

 

 

반응형