콘텐츠로 이동

자주 사용하는 명령어

author: Onejay
createdAt: 2024-08-18
updatedAt: 2024-08-19

  • 현재 상태Status를 확인
    • Branch Name
    • Remote Repo 의 상태(Fetch or Pull 해야할 내용이 있는지)
    • 현재 작업 중인 파일들의 상태 (stage 상태인지)
Terminal window
$ git status
On branch feature/example
Your branch is ahead of 'origin/feature/example' by 1 commit.
  • Git 이력 확인
    • git log -1 command 로 직전 커밋의 정보(작업자, 커밋일시, 커밋내용, Revision 등)를 확인할 수 있다.
Terminal window
$ git log -1
commit 14c65656386493c2108355a6d7345259bcf3f55d (HEAD -> feature/example)
Author: onejay <abcd1234@email.com>
Date: Sun Aug 11 15:54:53 2024 +0900
add new wiki
  • Commit 한 내용을 Remote Repo 에 upload
    • -f 옵션을 이용해 force upload 가능
    • git push ${REMOTE_NAME} ${BRANCH_NAME}
Terminal window
$ git push -f origin feature/example
Terminal window
$ git clone ${SSH_URL}
  • To see local branches

    Terminal window
    $ git branch
    * feature/example
    main
  • To see all local and remote branches

    Terminal window
    $ git branch -a
    * feature/example
    main
    remotes/origin/HEAD -> origin/main
    remotes/origin/feature/example
    remotes/origin/main
  • To see remote branches

    Terminal window
    $ git branch -r
    remotes/origin/HEAD -> origin/main
    remotes/origin/feature/example
    remotes/origin/main
  • To see branch name

    Terminal window
    $ git branch --show-current
    feature/example
  • To see revision

    Terminal window
    $ git rev-parse HEAD
    14c65656386493c2108355a6d7345259bcf3f55d
  • create a new branch

    Terminal window
    $ git branch ${NEW_BRANCH_NAME}
  • create a new branch and swtich to a branch

    Terminal window
    $ git checkout -b ${NEW_BRANCH_NAME}
  • switch to a branch in your local repo

    Terminal window
    $ git checkout ${BRANCH_NAME}
  • To delete a remote branch

    Terminal window
    $ git push origin --delete ${BRANCH_NAME}
  • To delete a local branch

    Terminal window
    $ git branch -d ${BRANCH_NAME}
    $ git branch -D ${BRANCH_NAME}
  • origin: alias of remote repo
  • git@gitlab.com ~ .git: remote repo url
Terminal window
$ git remote -v
origin git@gitlab.com:projects/sample1/ABCDE-service.git (fetch)
origin git@gitlab.com:projects/sample1/ABCDE-service.git (push)
Terminal window
$ git config --get remote.origin.url
git@gitlab.com:projects/sample1/ABCDE-service.git
  • git@gitlab.com:projects/sample1/ABCDE-service.git -> git@gitlab.com:projects/sample2/ABCDE-service.git
Terminal window
$ git remote set-url origin git@gitlab.com:projects/sample2/ABCDE-service.git