Git 기본 명령어


Intro

Git도 설치했고 Github로 원격저장소도 만들었으니 Git bash을 이용하여 기본 명령어들을 사용해보도록 하겠습니다.
(명령어는 계속 추가 할 계획 입니다.)

Git 버전 확인 (version)

$ git version
=> git version 2.27.0.windows.1

Git 도움말 (help)

$ git help
=> usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone             Clone a repository into a new directory
   init              Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add               Add file contents to the 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
   sparse-checkout   Initialize and modify the sparse-checkout

examine the history and state (see also: git help revisions)
   bisect            Use binary search to find the commit that introduced a bug
   diff              Show changes between commits, commit and working tree, etc
   grep              Print lines matching a pattern
   log               Show commit logs
   show              Show various types of objects
   status            Show the working tree status

grow, mark and tweak your common history
   branch            List, create, or delete branches
   commit            Record changes to the 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
   switch            Switch branches
   tag               Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   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

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.

Git 로컬저장소 생성하기 (init)

$ git init
=> Initialized empty Git repository in C:/AksStudio/repository/study/.git/
  • 아래와 같이 해당 폴더에 .git 파일이 생성 됩니다.
    (해당 폴더가 안보일 경우 폴더 내 숨김옵션 활성화 필요)

  • .git 폴더에는 Git 생성한 버전들의 정보, 원격저장소 주소 등 설정정보가 있습니다.
  • 통상 이를 “로컬저장소” 라고 부릅니다.

Git 설정정보 확인 및 변경하기 (config)

# 설정 정보 목록 확인
$ git config --list
=> diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
user.name=Aks
user.email=45597561+dhk5646@users.noreply.github.com
core.autocrlf=true
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true

# user.email 설정정보 변경 하기
$ git config --global user.email "dhk5646@gmail.com"

Git 로컬저장소 소스목록 추가하기 (add)

# 추가할 간단한 샘플 파일 생성 하기
echo "# study" >> README.md

# 소스목록 추가하기
$ git add README.md

Git 로컬저장소 소스 올리기 (commit)

$ git commit -m "커밋 설명"
=> [master (root-commit) cdf9734] 커밋 설명
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
  • m 옵션은 message

Git 커밋 이력 확인하기 (log)

$ git log
=> commit cdf9734c95b67ba35ad62d81a194a1eeb57255df (HEAD -> master)
Author: Aks <dhk5646@gmail.com>
Date:   Wed Mar 10 22:16:22 2021 +0900

    커밋 설명

Git 원하는 시점으로 파일 이동하기 (checkout)

# 가장 최신 revision 으로 이동
$ git checkout -

# 원하는 revision 으로 이동
$ git checkout 리비전정보

Git 원격저장소 주소 연동 및 끊기 (remote)

# 원격저장소 주소 연동 하기
$ git remote add origin https://github.com/aks0123/study.git

# 원격저장소 주소 연동 끊기
$ git remote rm origin

Git 원격저장소 소스 올리기 (push)

$ git push origin master
=> Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 224 bytes | 224.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/aks0123/study.git
 * [new branch]      master -> master

Git 원격저장소 복제하기 (clone)

$ git clone 원격저장소 주소 .
  • 가장뒤에 . 은 현재 작업위치를 나타내며 현재 위치에 파일을 풀겠다는 내용입니다.
  • 만약 . 을 입력하지 않을 경우 gitTest/”해당위치에 다운로드됨”

Git 원격저장소 소스 내려받기 (pull)

$ git pull origin master
  • clone 이후 동기화 처리 후 원격저장소에 새로운 커밋이 있을 경우 로컬저장소로 내려받습니다.

태그:

카테고리:

업데이트:

댓글남기기