git을 사용하면서 하나의 repository에 여러 하위 폴더들이 각각 업무에 맞게 사용하는것들이 있다. 그래서 자신의 맞는 업무의 경로(폴더)만 가져오고 push까지 하는 방법을 쓴다.
이 방법은 이미 clone한 프로젝트의 특정 경로 또는 파일만 가져오는게 아니라 처음부터 특정경로를 가져오는 방법이다.
git init
git remote add origin <"remote할 저장소.git">
git config core.sparsecheckout true
echo "해당경로" > .git/info/sparse-checkout
만약 vscode의 git의 원하는 경로를 가져오겠다 하면 주소창에 https://github.com/microsoft/vscode/tree/main/scripts 있는 뒷부분 경로를 넣어주어야 하는데(/vscode/tree/main/scripts) 이부분에 tree/main/ 부분이 포함되어 있으므로 그대로 하면 에러가 당연하게 난다.
그러므로 "vscode/scrips"식으로 넣어 주면 된다.
git pull origin master
sparse checkout을 통해 clone시에는 push가 정상 대로 안된다는 글이 있었는데 본인에 경우에는 기존 push 하는 방법과 마찬 가지로 했을 시 push가 가능했다.
만약 안된다면 https://bitlog.tistory.com/132 👈이 블로그를 참조!
git add .
# or
git add -A
git status
git commit -m "code update"
원격 저장소가 연결이 안되어 있다면 아래와 같이 remote를 해줘야 한다. 되어 있다면 pass!
git remote add origin <git 주소>
git push origin master
remote 했던 origin(다른 이름으로 했어도 무방)에 master 브런치에 push.
여러명에서 협업 중이고 충돌에 대비해 브런치를 쓰는게 일반적이고 보통이지만 그럴 일이 없다면 보통 master를 사용
브런치 사용시 push
# 브런치 변경(이전에 브런치를 생성했다는 기준!)
git branch -M <브런치 이름>
# push
git push origin <브런치 이름>
2022.06.15 추가
2.25 이후 버전을 쓰신다면 위에 방법이 안될 수도 있다.
참고 : https://bitlog.tistory.com/131#sparse-checkout%20(%20git%202.25%20~%20)
git --version
처음은 위의 방법과 다르진 않다.
cd <remote할 디렉토리>
git init
git sparse-checkout init
git sparse-checkout set "/<github pull 받을 부분만의 경로(다랙터리)>/"
git sparse-checkout list # git sparse-checkout list 시에 위의 set 해준 경로가 보인다.
# /<경로(다랙터리)>/
git remote add origin <"remote할 저장소.git">
git pull origin master
참조 : https://velog.io/@byjihye/git-clone
참조 : https://eventhorizon.tistory.com/20
참조 : https://bitlog.tistory.com/132