[GitHub] 명령어

kkiyou·2021년 6월 3일

GitHub

목록 보기
4/4

Git Commands(명령어)

1. help(도움말)

git help
git help tutorial
git help everyday
git help revisions
git help workflows
git help <command name>

2. start working area(만들기)

clone

git clone
새로운 directory로 Git repository(저장소)를 복제한다.


init

git init
기존에 존재하던 Git repository(저장소)를 다시 초기화하거나, 비어있는 Git repository(저장소)를 만든다.



3. work on the current change

add

git add <file name1> [<file name2> ...]
파일이나 폴더를 index에 추가한다.

git add .
현재 directory와 하위 directory에 위치한 모든 파일이나 폴더를 index에 추가한다.


mv

Move or rename a file, a directory, or a symlink


restore

Restore working tree files


rm

Remove files from the working tree and from the index



4. examine the history and state

diff

git diff
변경했으나, index에 추가되지 않은 변화들을 출력한다.


log

git log
commit log를 출력한다.

  • option
    • git --graph
      workflow(작업 흐름)을 시각화하여 출력한다.

    • git --oneline
      commit messeage만 한 줄로 출력한다.

status

현재재 working tree의 상태를 출력한다.


show

Show various types of objects


grep

git grep <pattern>
git에 있는 파일 내 문자열에서 pattern을 찾아 출력한다.


bisect

Use binary search to find the commit that introduced a bug



5. grow, mark and tweak your common history

branch

git branch
Git의 branch 목록을 출력한다. 이때 현재 working branch를 *로 강조한다.

  • option
    • git branch -m <old branch> <new branch>
      branch 이름을 old brach에서 new branch로 변경한다.

    • git branch -M <old branch> <new branch>
      branch 이름을 old brach에서 new branch로 강제로 변경한다.

    • git branch -d <branch name>
      branch를 Local repository에서 삭제한다.

    • git branch -D <branch name>
      branch를 Local repository에서 강제로 삭제한다.

    • git help branch
      branch 관련 도움말을 출력한다.

commit

repository에 변화를 기록한다.


merge

Join two or more development histories together


rebase

Reapply commits on top of another base tip


reset

Reset current HEAD to the specified state

기본 옵션값은 --mixed임.

  • option

    git reset --mixed <commit hash>
    되돌리기 전 데이터가 working directory에서 변경된 상태로 되돌린다. 즉 되돌리기 전 데이터가 추가된 상태이나, staging area에 올라가지 않은 상태이다.


    git reset --hard <commit hash>
    완전히 commit hash의 과거 상태로 되돌린다.


    git reset --soft <commit hash>
    되돌리기 전 데이터가 staging area에 add된 상태로 되돌린다.


    git reset HEAD~<n 개 전 commit>
    git reset HEAD<^> # ^의 갯수 당 1개 전으로 돌아감.


switch

git switch <branch name>
woriking branch를 변경한다.

Git 2.23부터 checkout을 switch와 restore로 분할시켰다. 여전히 checkout을 사용할 수 있지만, 업데이트에 맞춰 switch와 restore을 사용하는게 바람직하다.


tag

Create, list, delete or verify a tag object signed with GPG



6. collaborate

fetch

Download objects and refs from another repository


pull

Fetch from and integrate with another repository or a local branch


push

Update remote refs along with associated objects

  • option
    • git push origin --delete <branch name>
      Remote repository에서 branch를 삭제한다.

0개의 댓글