1. Config 관리

1) Config 정보 확인하기

git config --list
  • 나가기: q

2) Config 설정하기

core.editor 설정

git config --global core.editor "code --wait"    // visual studio code
git config --global core.editor "vim"
  • .gitmessage.txt를 통해 commit하기 위해서 설정한다.
  • .gitmessage.txt를 사용한다면 -m을 쓰지 않고 git commit만 실행한다.

➡️ visual studio code 일 경우

$ git commit
hint: Waiting for your editor to cloase the file...

[main (root-commit) a3bdb23] docs: 기본 template 생성
 2 files changed, 25 insertions(+)
 create mode 100644 .gitlab/merge_request_templates/Default.md
 create mode 100644 .gitmessage.txt

➡️ vim 일 경우

  • ESC key를 누르면 INSERT 모드로 변경됨
  • 나가기: :qw / :x

2. Commit

1) commit 취소하고 싶을 때

git reset --soft HEAD^

2) commit message 변경하고 싶을 때

git commit --amend

3. Push

1) 일반 push

git push origin main

2) push 취소하고 싶을 때

push 이전 commit 했던 내역이 없어지고, add 전으로 돌아간다.

git reset HEAD^

이후 강제로 push 해주어야 한다.

git push -f origin main

4. Pull

1) 강제로 git pull

  • 나의 local code에 상관없이 branch 코드를 덮어씌우고 싶을 때 사용
git fetch --all
git reset --hard origin/main
git pull origin main

5. Branch

1) Branch 확인

git branch
git branch -v                # branch details 

2) Branch 생성

git branch your_name

3) Branch Checkout

git checkout your_name
git checkout -b your_name    # create branch + checkout

6. .gitignore

1) 필요한 내용 찾기

2) .gitignore에 적용하기 전 이미 commit한 경우 삭제 방법

예를 들어 __pycache__ 폴더가 이미 git에 올라가 있다고 하자. 그렇다면 삭제 후 다시 commit하면 된다.

git ls-files '*.pyc' | xargs git rm -f

태그:

카테고리:

업데이트:

댓글남기기