git 정리

3 분 소요

user 등록

git config --global user.name "Your Name"
git config --global user.email "Your Email"

단축키 지정

git config --global alias.a "add"
git config --global alias.b "branch"
git config --global alias.c "checkout"
git config --global alias.cp "cherry-pick"
git config --global alias.co "commit"
git config --global alias.d "diff"
git config --global alias.ds "diff --staged"
git config --global alias.h '!git ls-files -v | grep "^[hS]"'
git config --global alias.l "log --oneline --graph -20 --pretty=format:'%C(Yellow)%h%C(reset) %s %C(auto)%d%C(reset) %C(dim white)%an%C(reset) %C(dim cyan)%ci%C(reset)'"
git config --global alias.ln "log --oneline --graph --no-merges -20 --pretty=format:'%C(Yellow)%h%C(reset) %s %C(auto)%d%C(reset) %C(dim white)%an%C(reset) %C(dim cyan)%ci%C(reset)'"
git config --global alias.ll "log --oneline --graph --all -20 --pretty=format:'%C(Yellow)%h%C(reset) %s %C(auto)%d%C(reset) %C(dim white)%an%C(reset) %C(dim cyan)%ci%C(reset)'"
git config --global alias.lln "log --oneline --graph --no-merges --all -20 --pretty=format:'%C(Yellow)%h%C(reset) %s %C(auto)%d%C(reset) %C(dim white)%an%C(reset) %C(dim cyan)%ci%C(reset)'"
git config --global alias.m "merge"
git config --global alias.p "pull"
git config --global alias.pp "push"
git config --global alias.r "restore"
git config --global alias.re "remote"
git config --global alias.s "status"
git config --global alias.st "stash"

github fork 최신버전 관리

  • fork repository 등록
    github에서 repository fork 사용시 fork쪽 remote branch 최신화 관리를 위해 등록.
git remote add <name> <url>
git remote add fork https://github.com/******/******.git
  • fork repository pull
git pull <name> <branch>
git pull fork main

git Bash 단축키

  • Moving
command description
ctrl + a Goto BEGINNING of command line
ctrl + e Goto END of command line
  • Edit
command description
ctrl + u Clear all / cut BEFORE cursor
ctrl + k Clear all / cut AFTER cursor
ctrl + w delete the word BEFORE the cursor
alt + d delete the word FROM the cursor
alt + [Backspace] delete PREVIOUS word
ctrl + y paste (if you used a previous command to delete)
ctrl + l Clear the screen (same as clear command)
ctrl + d Exit shell (same as exit command when cursor line is empty)
ctrl + _ Undo

git Bash 에서 탐색창 띄우기

start .

git diff

로컬에서 stage에 add하거나 commit 작업 전에 변경사항을 체크하기 위해 diff를 자주 사용하게 됩니다. 그런데 코드가 stage에 존재여부에 따라 diff 대상여부가 달라집니다.
staged

git diff --staged

not staged

git diff

git stash 생성시 메세지 지정

별다른 옵션이 없을 경우 작업한 branch명 기준으로 메세지가 생성됩니다. 이를 수동으로 지정하고 싶을 경우

git stash push -m "message"

//deprecated as of 2.15.x/2.16
git stash save "message"

.gitignore 정상처리 되지 않을 경우

이미 커밋이 된 코드를 .gitignore에 추가할 경우 ignore 적용이 되지 않을 것이다.
cached 날리고 delete 해버려서 정리해주자.

git rm -r --cached .
git add .
git commit -m "fixed untracked files"

원격 repository url 변경

git remote set-url <name> <newurl>
git remote set-url origin https://github.com/******/******.git

원격 branch 삭제

git push origin --delete <원격 branch명>

master branch main으로 변경

git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a

local branch 정리

git remote prune origin

git untracked 파일 삭제

git clean -fd

git Pull/Push할 때 id password 묻지 않게 하기

git config --global credential.helper store

git version update

version 2.14.1 : 새로 까세요.
version 2.14.2 ~ 2.16.1

git update

version 2.16.1(2) ~

git update-git-for-windows

git 로컬에서만 파일 무시하기

보통 환경설정 파일의 경우 개인로컬마다 차이가 발생할 수가 있다.
예를 들어 application-local.yml에서 h2 db의 url이 개일로컬의 특정 디렉토리를 가리키게 할 경우.
이럴 땐 변경 사항이 git tracking에서 제외하고 싶은데.
보통 git update-index 의 assume-unchanged 또는 skip-worktree 을 사용하는데 둘은 미묘한 차이가 있다.
결론적으로
--assume-unchanged 개발자가 파일을 변경 해서는 안 된는 경우. 예를 들어 library나 SDKs와 같이 변경되지 않는 폴더.
--skip-worktree 개발자가 파일 을 변경 해야 하는 경우. git에게 특정 파일을 건드리지 않도록 지시할 때 유용 합니다. 예를 들어 configuration 같은 구성 파일.
하지만 checkout시 변경사항 때문에 Aborting 될 것입니다.
https://stackoverflow.com/questions/29549318/not-possible-to-switch-branch-after-skip-worktree

--assume-unchanged

//설정
git update-index --assume-unchanged <files>
//설정된 파일 목록 보기
git ls-files -v | grep ^h
//해지
git update-index --no-assume-unchanged <files>

--skip-worktree

//설정
git update-index --skip-worktree <files>
//설정된 파일 목록 보기
git ls-files -v | grep ^S
//해지
git update-index --no-skip-worktree <files>

무시 설정된 파일 목록 보기 및 단축어 hidden 등록

//설정된 파일 목록 보기
git ls-files -v | grep ^[hS]
//hidden 단축어 등록
git config --global alias.hidden '!git ls-files -v | grep "^[hS]"'

git bash 느릴 때

git bash 사용 중 엄청 느려지는 현상이 발생했습니다. 도저히 사용 불가할 정도로…
stackoverflow 해결책
Aspire 노트북에서 발생한 현상이였는데 원인은 AMD Radeon 그래픽 드라이브. 혹시나 해서 2021년 최신 버젼 update를 했다가 컴퓨터가 먹통이 되는 현상까지 겪었습니다.
window 안전모드 들어가서 AMD Radeon 그래픽 카드 사용 안함으로 변경해서 겨우 정상 부팅하고. 삭제해버렸습니다.
어쨌든 AMD Radeon 그래픽 카드 사용 중지를 했을 때 git bash 느려지는 현상이 고쳐졌습니다.

Windows git-diff에서 CR(Carriage Return, ^M)을 무시하도록 하는 방법

git config --global core.whitespace cr-at-eol

git ssh

설치

https://www.lainyzine.com/ko/article/creating-ssh-key-for-github/ https://yangeok.github.io/git/2020/03/08/ssh-multiple-account.html

linux에서 WARNING: UNPROTECTED PRIVATE KEY FILE! 오류 발생시

https://www.lesstif.com/lpt/ssh-unprotected-private-key-file-80249001.html

Pro Git Book
효율적인 브랜치 관리
Git, Pull/Push할 때 id password 묻지 않게 하기

태그:

카테고리:

업데이트:

댓글남기기