# Git ์ฌ์ฉ๋ฐฉ๋ฒ
git config --global init.defaultBranch main
git --version
git config --global user.name "์ฌ์ฉ์๋ช
"
git config --global user.email "์ด๋ฉ์ผ"
git config --global init.defaultBranch main
git config --list
cd C:\Temp\sample
git init
git add *
git commit -m "์ค๋ช
"
git status
git remote add origin https://github.com/oseongryu/sample.git
git push origin main
# gitignore global
touch ~/.gitignore
git config --global core.excludesfile ~/.gitignore
# Git Revert
git log
git reset --hard "์ํ๋ HEAD"
git push -f origin main
# Git Reset
git reset HEAD^ // ๋ง์ง๋ง ์ปค๋ฐ ์ญ์
git reset --hard HEAD // ๋ง์ง๋ง ์ปค๋ฐ ์ํ๋ก ๋๋๋ฆผ
git reset HEAD * // ์คํ
์ด์ง์ ์ธ์คํ
์ด์ง์ผ๋ก ๋ณ๊ฒฝ
# git ๋ณํฉ์ทจ์
git merge --abort
# git config ์ค์ ์ ์ ์ฅ ์์น
System <git-install-root>\mingw64\etc\gitconfig gitconfig
Global C:\Users\username\.gitconfig .gitconfig
Local <git-repo>\.git\config config
Worktree <git-repo>\.git\config.worktree config.worktree
Portable C:\ProgramData\Git\config config
git config --global user.name "์ฌ์ฉ์๋ช
"
git config --global user.email "์ด๋ฉ์ผ"
git config --local user.name "์ฌ์ฉ์๋ช
"
git config --local user.email "์ด๋ฉ์ผ"
git config --list
# git branch
git checkout -b deploy/prod
git push origin deploy/prod
git branch --set-upstream-to origin/deploy/prod
### branch ์ญ์
git checkout amin
git branch --delete deploy/prod
git branch -D deploy/prod
git push origin :deploy/prod
# git rebase
git branch
git checkout develop
git push
git checkout feature/test
git rebase develop
git checkout develop
git merge feature/test --ff
# git ๋ก์ปฌ ๋ด์ฉ ์ ๋ฐ์ดํธ
git branch -r
git remote update
git branch -a
# git log
git log --oneline
git log --pretty=format:"%h - %an, %ar : %s"
git log --pretty=format:"%h %cd %an %s"
git log --stat
git log --pretty=format:"%h %cd %an %s" --since="2022-11-01" --until="2022-11-30" --committer=aaaa --committer=bbbb --committer=cccc
git log --pretty=format:"%h %cd %an %s" --since="2022-12-01" --until="2022-12-31" --committer=aaaa --committer=bbbb --committer=cccc
git log --pretty=format:"%h %cd %an %s" --since="2023-01-01" --until="2023-01-31" --committer=aaaa --committer=bbbb --committer=cccc
# ํ์ผ๋ชฉ๋ก ์ถ๊ฐํ์ธ
git log --name-only --pretty=format:"%h %cd %an %s" --since="2022-11-01" --committer=aaaa
# ํ์ผ๋ชฉ๋ก ์ ๋ ฌ ๋ฐ ํ๋๋ก ํตํฉ
git log --name-only --pretty=format: --since="2022-02-01" --committer=aaa | sort | uniq
# ๋ฆฌ๋ ์ค ๊ถํ ๋ฌธ์ ๊ด๋ จ์ด ์์ ๊ฒฝ์ฐ (.git์ ํด๋์์ ํ์ธ)
Unable to create '/home/user/repo/.git/refs
chown -R user:usergroup file/folder
# ๋งฅ์์ git ๊ณ์ 2๊ฐ ์ด์ ์ฌ์ฉ ์ ssh ์ธ์ฆ
### ssh-keygen ์์ฑ
cd ~/.ssh or mkdir ~/.ssh
ssh-keygen -t <์ํธํ๋ฐฉ์> -b <keyํฌ๊ธฐ ๊ธฐ๋ณธ3072> -C '๊นํ๋ฑ๋ก๋ฉ์ผ@๋ฉ์ผ.com'
ssh-keygen -t rsa -b 4096 -C 'myuser@email.com'
ssh-keygen -t rsa -b 4096 -C 'oseongryu@gmail.com'
Enter file in which to save the key (/Users/${USER}/.ssh/id_rsa): <id_rsa_์ด๋ฆ์ง์ >
Enter file in which to save the key (/Users/${USER}/.ssh/id_rsa): id_rsa_myuser
Enter file in which to save the key (/Users/${USER}/.ssh/id_rsa): id_rsa_oseongryu
eval "$(ssh-agent -s)"
ssh-add <keyํ์ผ๊ฒฝ๋ก>
ssh-add ~/.ssh/id_rsa_myuser
ssh-add ~/.ssh/id_rsa_oseongryu
ssh-add -l
* ์ญ์ ํ ๋ค์ ๋ง๋ค ํ์๊ฐ ์๋ ๊ฒฝ์ฐ
ssh-add -D
touch ~/.ssh/config
vi ~/.ssh/config
--- ํด๋น ๋ด์ฉ ์ถ๊ฐ
# Git myuser
Host github.com-myuser
HostName github.com
IdentityFile ~/.ssh/id_rsa_myuser
User myuser
# Git oseongryu
Host github.com-oseongryu
HostName github.com
IdentityFile ~/.ssh/id_rsa_oseongryu
User oseongryu
### github > settings > SSH and GPG keys >> New SSH Key
pbcopy < ~/.ssh/id_rsa_f5074.pub
### ํ
์คํธ
ssh -T git@github.com-myuser
### ์ฌ์ฉ
git remote add origin git@github.com-oseongryu:oseongryu/til.git
git remote set-url origin git@github.com-oseongryu:oseongryu/til.git
# ๋ค๋ฅธ ๋งฅ์ผ๋ก .ssh์ค์ ์ฎ๊ธฐ๊ธฐ
๋ค๋ฅธ ๋งฅ์์ .ssh ํ์ผ๋ง ์ฎ๊ฒจ์ฌ ๊ฒฝ์ฐ ์๋์ ๊ฐ์ ์๋ฌ๊ฐ ๋ํ๋ ์ ์์
private key์ permissions์ด ๋ง์ด ๋์ด ์์ด์ ์๊ธฐ๋ ๋ฌธ์ ์์
์ฎ๊ฒจ์จ ํ์ผ์ ๊ถํ์ ๋ณ๊ฒฝํด์ ์ฒ๋ฆฌ
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chmod 644 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/known_hosts
---
Warning: Permanently added 'github.com,64:ff9b::344e:e76c' (RSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/Users/oseongryu/.ssh/id_rsa_oseongryu' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/Users/oseongryu/.ssh/id_rsa_oseongryu": bad permissions
---
# ์๊ฒฉ์์ ssh์ค์ ์
chown $USER ~/.ssh/config
chmod 644 ~/.ssh/config
# git Commit Message Structure
feat : ์๋ก์ด ๊ธฐ๋ฅ ์ถ๊ฐ
fix : ๋ฒ๊ทธ ์์
docs : ๋ฌธ์ ์์
style : ์ฝ๋ ํฌ๋งทํ
, ์ธ๋ฏธ์ฝ๋ก ๋๋ฝ, ์ฝ๋ ๋ณ๊ฒฝ์ด ์๋ ๊ฒฝ์ฐ
refactor : ์ฝ๋ ๋ฆฌํํ ๋ง
test : ํ
์คํธ ์ฝ๋, ๋ฆฌํํ ๋ง ํ
์คํธ ์ฝ๋ ์ถ๊ฐ
chore : ๋น๋ ์
๋ฌด ์์ , ํจํค์ง ๋งค๋์ ์์
feat: (new feature for the user, not a new feature for build script)
fix: (bug fix for the user, not a fix to a build script)
docs: (changes to the documentation)
style: (formatting, missing semi colons, etc; no production code change)
refactor: (refactoring production code, eg. renaming a variable)
test: (adding missing tests, refactoring tests; no production code change)
chore: (updating grunt tasks etc; no production code change)
# git local pull request
#### local get pull request
git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"
git fetch origin
git checkout -t origin/pr/35
s#### config ์ถ๊ฐ
git config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
#### config ์ญ์
git config --unset --local remote.origin.fetch
git config --unset-all --local remote.origin.fetch
git config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
# fetch github pr to local
git pull origin pull/35/head
-- git config์ ์ค์
[alias]
pr = "!f() { git fetch -fu ${2:-origin} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f"
pr-clean = "!git for-each-ref refs/heads/pr/* --format='%(refname)' | while read ref ; do branch=${ref#refs/heads/} ; git branch -D $branch ; done"
git pr 35
git pr-clean
# SSL certificate problem: self signed certificate in certificate chain
git config --global http.sslVerify false
# git remote origin
# 1
git config --local --list
git remote add origin git@github.com:oseongryu/til.git
git remote remove origin
git config --local --list
git remote add origin git@github.com:oseongryu/til.git
git push -u origin main
# 2
git remote set-url origin git@github.com:oseongryu/til.git
# git merge option
git merge [branch] --strategy-option ours
git merge [branch] --strategy-option theirs
#### fast-forward ๊ด๊ณ์ ์์ผ๋ฉด commit์ ์์ฑํ์ง ์๊ณ ํ์ฌ ๋ธ๋์น์ ์ฐธ์กฐ ๊ฐ ๋ง ๋ณ๊ฒฝ(default)
git merge --ff [branch]
#### fast-forward ๊ด๊ณ์ ์์ด๋ merged commit ์์ฑ
git merge --no-ff [branch]
#### fast-forward ๊ด๊ณ์ ์์ด๋ merged commit ์์ฑ, merging ๋ธ๋์น ์ ๋ณด ์๋ต
git merge --squash [branch]
# git remove specific file on all commit
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch ํ์ผ๋ช
' --prune-empty --tag-name-filter cat -- --all
git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch 99_00_Software/[IntelliJ].md' --prune-empty --tag-name-filter cat -- --all
# git stage to unstage
git reset HEAD -- .
# git discard change
git restore .
git reset --hard
# git Directory ๊ณ์ ์ค์
git config --list --show-origin
.gitconfig(์ ์ธ)
---
[user]
email = oseongryu@gmail.com
name = oseongryu
---
.gitconfig(์ถ๊ฐ)
---
[includeIf "gitdir:~/git/personal/"]
path = .gitconfig-personal
[includeIf "gitdir:~/git/professional/"]
path = .gitconfig-professional
---
.gitconfig-personal(์ถ๊ฐ)
---
[user]
email = oseongryu@gmail.com
name = oseongryu
---
.gitconfig-professional(์ถ๊ฐ)
---
[user]
email = osryu@gmail.com
name = osryu
---
# ๋ฆฌ๋ชจํธ ๋ธ๋์น ์ฐธ์กฐ ์ ๋ฐ์ดํธ
# ๋ฆฌ๋ชจํธ ๋ธ๋์น์ ๋ ์ด์ ์ ํจํ์ง ์์ ์ฐธ์กฐ๋ฅผ ๊นจ๋์ด ์ง์ฐ๋ ๋ช
๋ น์ด
git remote prune origin
git remote update --prune
# ๋ก์ปฌ ์ ์ฅ์๋ฅผ ์ต์ ์ ๋ณด๋ก ๊ฐฑ์ (๋ฆฌ๋ชจํธ ์ ์ฅ์์ ๋๊ธฐํ)ํ๋ฉฐ ์๋์ ์ผ๋ก ๋์ด์ ์ ํจํ์ง ์์ ์ฐธ์กฐ๋ฅผ ์ ๊ฑฐ
git fetch -p
# ์ค์๋ก ์ญ์ ํ ๋ธ๋์น ๋ณต๊ตฌํ๊ธฐ
git reflog
git checkout -b 'temp' HEAD@{1}
# ์๊ฒฉ ๋ธ๋์น ์ญ์
git push origin --delete feature/oseongryu
# git ์ปค๋ฐ์ด ์๋ชป๋์ด ๋ณต๊ตฌํ๋ ๋ฐฉ๋ฒ
// 1. ๋ฐฉ๋ฒ
1. ๋ก๊ทธ๋ก ํน์ ๋ถ๋ถ ํค๋ ํ์ธ
git log --pretty=format:"%h %cd %an %s" --since="2022-11-01" --until="2022-11-30" --committer=aaaa --committer=bbbb --committer=cccc
git log --pretty=format:"%h %cd %an %s" --since="2022-12-01" --until="2022-12-31" --committer=aaaa --committer=bbbb --committer=cccc
git log --pretty=format:"%h %cd %an %s" --since="2023-01-01" --until="2023-01-31" --committer=aaaa --committer=bbbb --committer=cccc
2. cherry-pick๋ฅผ ์ฌ์ฉํด์ ํตํฉ
// 2. ๊ฐํธ ๋ฐฉ๋ฒ
์ต์ด ๋๋ฆด ๋ถ๋ถ์ผ๋ก git reset --soft [HEAD๋ช
] ์ผ๋ก ๋๋ฆฐํ
git status๋ก ์์ ํ ํ์ผ์์ ์์ ์ด ์์ ํ ํ์ผ๋ชฉ๋ก ํ์ธ
# ssh config (github, gitblit, gitlab)
# 2022.09.23. github oseongryu
Host github.com
HostName github.com
Port 22
IdentityFile ~/.ssh/id_rsa_oseongryu
User oseongryu
# 2022.09.23. gitlab osryu
Host corporation.gitlab.com
HostName corporation.gitlab.com
# Port 22
IdentityFile ~/.ssh/id_rsa
User osryu
# 2022.09.23. gitblit osryu
Host corporation.gitblit.com
HostName corp.gitblit.com
Port 29418
IdentityFile ~/.ssh/id_rsa
User osryu
PubkeyAcceptedAlgorithms +ssh-rsa
HostKeyAlgorithms +ssh-rsa
# git stash
git stash
git stash save
git stash list
git stash apply
git stash apply stash@{0}
git stash drop stash@{0}
git stash pop
# gitlab
๋ฐ์ดํฐ์ด๊ด
https://trytoso.tistory.com/1313
์ผ๋ถ ํ์ผ๋ง Merge
git checkout -p [๊ฐ์ ธ์ฌ ํ์ผ์ด ์๋ branch๋ช
] [๊ฐ์ ธ์ฌ ํ์ผ์ ๊ฒฝ๋ก]
# ํ์ฌ ์์
์ค์ธ(checkout) ๋ธ๋์น๋ feature/devMain์ผ๋ก ๊ฐ์
$ git checkout -p feature/pubMain \client\components\pages\common\NavTab.vue
y - stage this hunk โ ํ์ด์ง ๋จ์ ์น์ธ
n - do not stage this hunk
q - quit; do not stage this hunk nor any of the remaining ones
a - stage this hunk and all later hunks in the file โ ์ผ๊ด ์น์ธ
d - do not stage this hunk nor any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
Origin/main์ ์์ค๋ก ๊ฐ์ ์ ์ฉ
# ์๋ฌด๊ฒ๋ ๋ณํฉํ๊ฑฐ๋ ๋ฆฌ๋ฒ ์ด์ค ํ์ง ์๊ณ ์๊ฒฉ์ง์์ ์ต์ ์ปค๋ฐ ์ ๋ณด๋ฅผ ๋ค์ด๋ก๋
$ git fetch --all
# ํ์ฌ ์์
์ค์ธ ๊ฒ์ ๋ฐฑ์
๋ธ๋์น๋ก ๋ถ๊ธฐ(ํ์์)
$ git branch backup-main
# ๊ฐ์ ๋ก ๋ด๋ ค๋ฐ๊ณ ์ ํ๋ ๋ธ๋์น๋ก ๋ฆฌ์
# --hard ์ต์
์ ๋ก์ปฌ์ ์ถฉ๋ ๊ฐ๋ฅํ ์์ ์ฌํญ์ด ์์ด๋ ๋ฌด์ํ๊ณ ๋ด๋ ค๋ฐ์
$ git reset --hard origin/main
$ git reset --hard origin/<branch_name>
# git submodules
git submodule add git@github.com:oseongryu/corp-script.git
git submodule add git@github.com:oseongryu/corp-script.git 00_corp_script
### remove
To remove a submodule you need to:
1. Delete the relevant section from the .gitmodules file.
2. Stage the .gitmodules changes:
git add .gitmodules
3. Delete the relevant section from .git/config.
4. Remove the submodule files from the working tree and index:
git rm --cached path_to_submodule (no trailing slash).
5. Remove the submodule's .git directory:
rm -rf .git/modules/path_to_submodule
6. Commit the changes:
git commit -m "Removed submodule <name>"
7. Delete the now untracked submodule files:
rm -rf path_to_submodule
git submodule init
git submodule update
git submodule foreach git checkout main
# git bash zip
C:\Program Files\Git\mingw64\bin https://stackoverflow.com/questions/38782928/how-to-add-man-and-zip-to-git-bash-installation-on-windows
- Navigate to this sourceforge page (opens new window)
- Download zip-3.0-bin.zip
- In the zipped file, in the bin folder, find the file zip.exe.
- Extract the file zip.exe to your mingw64 bin folder (for me: C:\Program Files\Git\mingw64\bin)
- Navigate to to this sourceforge page (opens new window)
- Download bzip2-1.0.5-bin.zip
- In the zipped file, in the bin folder, find the file bzip2.dll
- Extract bzip2.dll to your mingw64\bin folder (same folder as above: C:\Program Files\Git\mingw64\bin)
# git status filename oneline
git status --porcelain | sed s/^...//
git status -s | cut -c4-
git diff --name-only
git diff --name-only --staged
git diff --name-only HEAD
# git add ์ทจ์ํ๊ธฐ(unstage๋ก ๋ณ๊ฒฝ)
git add .
# ์ ์ฒด ๋๋๋ฆฌ๊ธฐ
git reset HEAD
# ํน์ ํ์ผ ๋๋๋ฆฌ๊ธฐ
git restore --staged filename
# git ํน์ ์ปค๋ฐ ์ด๋ฏธ์ง ํ์ผ์ด ์ฌ๋ผ์ง์ง ์๋ ๊ฒฝ์ฐ
ํน์ ์ปค๋ฐ ์ด๋ฏธ์ง ํ์ผ์ด ๊น์ผ๋ก ์ญ์ ๊ฐ ๊ณ์ ๋จ๋ ๊ฒฝ์ฐ
.git > config ํ์ผ์ ํด๋น ๋ด์ฉ์ด ์ฌ๋ผ์ง
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
ignorecase = true
# git ํน์ ํ์ผ์ ์์ ์ฌํญ ๋ฌด์
# ํน์ ํ์ผ์ ์์ ์ฌํญ ๋ฌด์ํ๊ธฐ
git update-index --assume-unchanged [file path]
# ํน์ ํ์ผ์ ์์ ์ฌํญ ๋ฌด์ ์ทจ์ํ๊ธฐ
git update-index --no-assume-unchanged [file path]
# ์์ ์ฌํญ ๋ฌด์ ํ์ผ ์กฐํ
git ls-files -v|grep '^h'
# git lcoal์์๋ง ์ ์ฉ
# 1
vim .git/info/exclude
git update-index --skip-worktree .vscode/launch.json
git update-index --no-skip-worktree .vscode/launch.json
# 2
git update-index --assume-unchanged .vscode/launch.json
git update-index --no-assume-unchanged .vscode/launch.json
git ls-files -v | grep '^[[:lower:]]'
# git push ํ์ง ์์ ๋ชฉ๋ก ํ์ธ
git log --branches --not --remotes
git log --branches --not --remotes --oneline --graph --decorate
# git log clear
git reflog expire --expire=now --all
git gc --aggressive --prune=all
# git alias
# https://hannut91.github.io/blogs/git/config
git config --global alias.cm commit
git config --global alias.co checkout
# ๋จธ์ง๋ ๋ธ๋์น ์ผ๊ด์ญ์ (.gitconfig)
[alias]
cleanbranch = "!git branch -d $(git branch --merged | grep -v '\\<master\\>')"
# git .gitattributes
# https://git-scm.com/book/ko/v2/Git๋ง์ถค-Git-Attributes
* text eol=lf
*.png binary
*.gif binary
*.woff binary
*.woff2 binary
*.otf binary
*.zip binary
* linguist-vendored
*.py linguist-vendored=false
# *.js linguist-detectable=false
# *.html linguist-detectable=false
# *.css linguist-detectable=false
# *.scss linguist-detectable=false
# git proxy (ssh, http)
# 1.ssh (git clone git@github.com:kubernetes/kubernetes.git)
# add ProxyCommand in ~/.ssh/config
Host github.com
HostName github.com
Port 22
IdentityFile ~/.ssh/id_rsa
User oseongryu
ProxyCommand nc -x 192.0.0.4:8000 -X connect %h %p #mac
# ProxyCommand connect -S 192.0.0.4:8000 %h %p # ServerAliveInterval 10 #Windows
# only cli
git -c "http.proxy=192.0.0.4:8000" clone git@github.com:oseongryu/docker-composes.git
# 2.http (git clone https://github.com/kubernetes/kubernetes.git)
# add config in "~/.gitconfig"
git config --global http.proxy http://192.0.0.4:8000
git config --global https.proxy https://192.0.0.4:8000
git config --global http.proxy 'socks5://192.0.0.4:8000'
git config --global https.proxy 'socks5://192.0.0.4:8000'
# References
Git Portable Location
https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/Where-system-global-and-local-Windows-Git-config-files-are-saved
https://trustyoo86.github.io/git/2017/11/28/git-remote-branch-create.html
https://velog.io/@hwang-eunji/github-2%EA%B0%9C-%EA%B3%84%EC%A0%95-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0
https://trustyoo86.github.io/git/2017/11/28/git-remote-branch-create.html
https://beomseok95.tistory.com/167#google_vignette
git rebase: https://junlab.tistory.com/m/203
https://doublesprogramming.tistory.com/256
git local pull request: https://blog.outsider.ne.kr/1204
git cherry-pick: https://gitbetter.substack.com/p/how-to-use-git-cherry-pick-effectively
git submodule: https://pinedance.github.io/blog/2019/05/28/Git-Submodule
โ - fiddler - github-action โ