자주 사용하는 명령어
Git 명령어
섹션 제목: “Git 명령어” author: Onejay createdAt: 2024-08-18 updatedAt: 2024-08-19Status
섹션 제목: “Status”Git Status
섹션 제목: “Git Status”- 현재 상태Status를 확인
- Branch Name
- Remote Repo 의 상태(Fetch or Pull 해야할 내용이 있는지)
- 현재 작업 중인 파일들의 상태 (stage 상태인지)
$ git status
On branch feature/example Your branch is ahead of 'origin/feature/example' by 1 commit.Git Log
섹션 제목: “Git Log”- Git 이력 확인
git log -1command 로 직전 커밋의 정보(작업자, 커밋일시, 커밋내용, Revision 등)를 확인할 수 있다.
$ git log -1
commit 14c65656386493c2108355a6d7345259bcf3f55d (HEAD -> feature/example) Author: onejay <abcd1234@email.com> Date: Sun Aug 11 15:54:53 2024 +0900
add new wikiPush
섹션 제목: “Push”Git Push
섹션 제목: “Git Push”- Commit 한 내용을 Remote Repo 에 upload
-f옵션을 이용해 force upload 가능git push ${REMOTE_NAME} ${BRANCH_NAME}
$ git push -f origin feature/exampleClone
섹션 제목: “Clone” $ git clone ${SSH_URL}Branch
섹션 제목: “Branch”List
섹션 제목: “List”-
To see local branches
Terminal window $ git branch* feature/examplemain -
To see all local and remote branches
Terminal window $ git branch -a* feature/examplemainremotes/origin/HEAD -> origin/mainremotes/origin/feature/exampleremotes/origin/main -
To see remote branches
Terminal window $ git branch -rremotes/origin/HEAD -> origin/mainremotes/origin/feature/exampleremotes/origin/main -
To see branch name
Terminal window $ git branch --show-currentfeature/example -
To see revision
Terminal window $ git rev-parse HEAD14c65656386493c2108355a6d7345259bcf3f55d
Create
섹션 제목: “Create”-
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
섹션 제목: “Switch”-
switch to a branch in your local repo
Terminal window $ git checkout ${BRANCH_NAME}
Delete
섹션 제목: “Delete”-
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}
Remote Repo
섹션 제목: “Remote Repo”Confirm Remote Repo
섹션 제목: “Confirm Remote Repo”origin: alias of remote repogit@gitlab.com ~ .git: remote repo url
$ git remote -v
origin git@gitlab.com:projects/sample1/ABCDE-service.git (fetch) origin git@gitlab.com:projects/sample1/ABCDE-service.git (push) $ git config --get remote.origin.url
git@gitlab.com:projects/sample1/ABCDE-service.gitChange Remote Repo URL
섹션 제목: “Change Remote Repo URL”git@gitlab.com:projects/sample1/ABCDE-service.git->git@gitlab.com:projects/sample2/ABCDE-service.git
$ git remote set-url origin git@gitlab.com:projects/sample2/ABCDE-service.git