728x90

👉 기본 환경

- Git Bash

 

 

⌨️ 코드

1
2
git add 오랜_기간_보호한_동물(1)_1.sql
 
 

 

 

🖨️오류

1
2
bash: syntax error near unexpected token '('
 
 

 

 

📡 원인

파일명에 괄호 또는 띄어쓰기가 있을 경우

 

 

📰 해결 방법

1
2
3
4
git add '오랜_기간_보호한_동물(1)_1.sql'
git add "오랜_기간_보호한_동물(1)_1.sql"
git add 오랜_기간_보호한_동물\(1\)_1.sql
 
 

- 작은 따옴표

- 큰 따옴

- 백 슬래시(이스케이프 문자)

 

728x90
728x90

👉 기본 환경

- Git Bash

 

 

⌨️ 코드

1
2
3
4
5
6
7
# git push origin --delete feat/3
git push remote_name --delete branch_name
 
# 동일한 기능
# git push origin :feat/3
git push remote_name :branch_name
 
 

 

 

🖨️오류

1
2
error: unable to delete feat/3: remote ref does not exist
 
 

 

 

📡 원인

원격 서버에 삭제하려는 branch가 존재하지 않음

 

🚨 전체 branch 조회 시, 삭제하고자하는 branch 조회

1
2
git branch -a
 
 

원격 branch만 조회할 경우,

1
2
git branch -r
 
 

 

⭐ 로컬에 기록되어있는 remote 서버 branch 정보와 실제 remote 서버 branch 정보가 일치하지 않음

로컬 pc의 remote branch 정보를 동기화 된지 오래된 경우, 문제 발생

 

 

📰 해결 방법

1
2
git fetch -p origin
 
 

fetch 명령어를 통해서 실제 remote 서버의 branch 정보를 가져와 로컬 pc에 갱신

-p: 가지치기(prune)

 

 

 

📚 참고 자료

 

[Git] 오류 해결 error: unable to delete '브랜치명': remote ref does not exist

gitlab으로 협업을 하다 보니까 git branch가 많이 쌓이게 되어 정리를 하였다.로컬 브랜치는 알아서 개인적으로 하면 되지만 remote는 별도로 관리하지 않으면 방치가 될 수 있다.git remote branch를 정리

velog.io

 

[Git] 원격 저장소 연결 및 끊기 원격브랜치 갱신, 조회, 삭제

협업을 하다보면 로컬 저장소(local repository)와 구분되게 원격 저장소(remote repository)를 연결해야 할 때가 있다. 현재 연결되어 있는 원격 저장소(remote repository) 확인 $ git remote -v 원격 저장소 연결 $

hu-coding.tistory.com

 

브랜치를 로컬과 원격에서 모두 삭제하는 법

깃 브랜치를 삭제하는 법은 간단하다. 로컬과 원격 두군데에서 모두 브랜치를 삭제하는 법을 알아보자. 간단히 요약하자면 아래와 같다. // 로컬에서 브랜치 삭제하기 명령어 git branch -d localBranch

www.freecodecamp.org

 

 

 

 

728x90
728x90

1. 기존에 생성한 repo에 접속

 

2. 연결하고자하는 폴더에서 오른쪽 마으스 클릭 후 Git Bash Here 실행

* Git Bash를 설치했으나 Git Bash Here이 나타나지 않을 경우 OverFlow 참조

 

3. 명령어 실행(다운로드)

git clone https://github.com/HJ0216/TIL.git

: remote repo에 있는 데이터를 최초로 다운받을 때 사용하는 명령어

 * 원격 repo 주소 복사하는 방법

 

cf. 숨김폴더 .git

: 일반 폴더를 깃이 관리할 수 있는 저장소로 변경되면서 생기는 것으로 git 저장소의 개념

: clone과 달리 push나 pull 명령어를 사용할 때는 git init을 통해 생성해야 함

 

git init

: .git, git 저장소 생성

 

git remote add origin https://github.com/HJ0216/TIL.git

: 원격 repo와 local 저장소 연결

 

git remote -v

: 원격 repo와 연결 상태 확인

 

git pull origin main

: remote repo에서 변경된 내용을 local 저장소에 반영

 

* fetch: 단순 변경사항 가져오기, remote와 local의 차이에 대한 merge 실행 X > 변경사항 확인 후, 수동 merge 진행

* pull: fetch + merge

* merge: remote repo 소스와 local 저장소의 비교하여 remote repo 소스가 더 최신 버전일 경우, local 소스 변경

 

4. 명령어 실행(업로드)

git status

Local PC(Working Dir) ▶ 가상공간: Index(Staging aread) ▶ Remote repo(Head-repo)

Working Dir과 Stage와의 차이 확인

 

git add.

: remote repo에 저장하기 전 Stage에 올려두는 명령어

: add . - 모든 변경사항 / add 파일명 - 해당 파일만

 * staging 삭제: git rm --cached 파일명

 

git commit -m "commit message"

: 커밋 및 commit msg 작성

 

git push origin main

: origin-원격 저장소 명

: main-branch 명

 

➕ 추가 명령어

git remote set-url origin repo_url

: local PC에서 연결된 remote repo를 다른 remote repo로 변경

git push -f origin branch_name

: local PC 내용을 remote repo로 강제 push

git remote remove origin

: local PC와 remote repo와 연결 해제

 

 

 

참고 자료

📑 [Github] Repository(레파지토리)에 Git clone/pull/push하기

📑 [Git] 원격 저장소 연결 및 끊기 (git remote)

 

728x90
728x90

1. Git bash에서 remote repository 변경 전 pull을 통해 버전 맞추기

$ git pull origin main
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 9 (delta 6), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), 2.10 KiB | 46.00 KiB/s, done.
From https://github.com/HJ0216/TIL
 * branch            main       -> FETCH_HEAD
   1843ac3..8797bb6  main       -> origin/main
Updating 1843ac3..8797bb6
Fast-forward
 README.md | 3 +++
 1 file changed, 3 insertions(+)

 

 

2. remote repository 내 불필요한 파일 제거

$ git rm --cached -r test.txt
rm 'test.txt'

# remote repository 내 불필요한 test.txt 파일 제거

 

폴더 제거 시,

git rm --cached -r 폴더명

# rm: remove
# --cached: 원격 저장소의 폴더 또는 파일 삭제 옵션
# --cached가 없을 경우, 로컬 저장소의 폴더 또는 파일도 삭제
# -r: directory 옵션

 

파일 제거 시,

git rm --cached -r 파일명
git rm --cached 파일명

# 둘 중 택 1
# -r 옵션은 폴더를 지울 때는 필수, 파일을 지울 때는 선택

 

 

3. 버전 관리를 위한 commit 진행

$ git commit -m "remove a test.txt"
[main 759bd78] remove a test.txt
 1 file changed, 1 deletion(-)
 delete mode 100644 test.txt

 

 

4. 원격 저장소로 push

$ git push -u origin main
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 223 bytes | 223.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/HJ0216/TIL.git
   8797bb6..759bd78  main -> main
branch 'main' set up to track 'origin/main'.

 

 

➕ --cached를 입력하지 않았을 때, remote repository와 local repository

1. 임의 파일(will_be_deleted.txt) 생성

2. git bash에서 add, commit, push 진행

$ git add /c/git_total/will_be_deleted.txt


$ git commit -m "add a test file for git pratice"
[main ed8b4a2] add a test file for git pratice
 1 file changed, 1 insertion(+)
 create mode 100644 will_be_deleted.txt


$ git push -u origin main
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 340 bytes | 340.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/HJ0216/TIL.git
   567d81d..ed8b4a2  main -> main
branch 'main' set up to track 'origin/main'.

3. remote repository에서 push 내용 확인

4. git bash에서 --cached 제외하고 파일 remove 진행

$ git rm will_be_deleted.txt
rm 'will_be_deleted.txt'

$ git commit -m "remove a test file for git pratice"
[main 95467dc] remove a test file for git pratice
 1 file changed, 1 deletion(-)
 delete mode 100644 will_be_deleted.txt

$ git push -u origin main
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 231 bytes | 231.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/HJ0216/TIL.git
   ed8b4a2..95467dc  main -> main
branch 'main' set up to track 'origin/main'.

5. remote repository 및 local repository에서 push 내용 확인

 

 

 

참고 자료

📑 [git] github에 잘못 올라간 폴더 및 파일 삭제하기

 

728x90
728x90

발생 Error

Git Bash에서 다음 명령어를 입력할 경우,

$ git pull origin main
remote: Enumerating objects: 247, done.
remote: Counting objects: 100% (247/247), done.
remote: Compressing objects: 100% (187/187), done.
remote: Total 247 (delta 73), reused 157 (delta 38), pack-reused 0
Receiving objects: 100% (247/247), 59.49 KiB | 378.00 KiB/s, done.
Resolving deltas: 100% (73/73), done.
From https://github.com/HJ0216/TIL
 * branch            main       -> FETCH_HEAD
 * [new branch]      main       -> origin/main

fatal: refusing to merge unrelated histories

fatal: refusing to merge unrelated histories

Error 발생

 

 

Error 원인

pull 명령어는 fetch와 merge를 한 번에 처리하는 명령어인데, merge가 되지 않는 상황

(fetch: 원격 저장소 내용 가져오기, merge: 로컬 저장소의 내용과 원격 저장소의 내용 병합하기)

 

push 명령은 로컬 저장소의 commit log와 원격 저장소의 commit log를 보고, 원격 저장소의 마지막 commit id와 동일한 commit id를 가진 로컬 저장소의 commit 시점을 찾아낸 뒤, 원격 저장소의 마지막 commit과 연결

 

commit histories가 서로 관련이 없을 경우, 즉 공통된 commit 지점이 존재하지 않을 경우, merge할 수 없음

 

 

해결 방법

1. git clone 명령어를 통해 원격 저장소 복제

2. pull 명령어 + 옵션을 통해 merge 진행

$ git pull origin main --allow-unrelated-histories
From https://github.com/HJ0216/TIL
 * branch            main       -> FETCH_HEAD
Merge made by the 'ort' strategy.
 AI/ann_model.py                   |  65 +++++++++++++++++
 AI/dacon_seoul_ddarung.py         | 103 ++++++++++++++++++++++++++
 AI/data_shape.py                  |  90 +++++++++++++++++++++++
 AI/evaluate_and_predict.py        |  51 +++++++++++++
 AI/hyperParameter_Tuning.py       |  40 ++++++++++
 AI/indicator_with_california.py   |  61 ++++++++++++++++
 AI/mae_and_mse.py                 |  48 ++++++++++++
 AI/matplotlib_plot2.py            |  44 +++++++++++
 AI/matplotlib_scatter_and_plot.py |  81 +++++++++++++++++++++
 AI/missing_value_handling.py      | 149 ++++++++++++++++++++++++++++++++++++++
 AI/multiLayer_Perceptron.py       |  74 +++++++++++++++++++
 AI/r2_score.py                    |  64 ++++++++++++++++
 AI/rmse_def.py                    |  63 ++++++++++++++++
 AI/split_train_test1.py           |  51 +++++++++++++
 AI/split_train_test2.py           |  58 +++++++++++++++
 AI/split_train_test3.py           |  68 +++++++++++++++++
 AI/useful_method_from_numpy.py    |  18 +++++
 README.md                         |  68 +++++++++++++++++
 18 files changed, 1196 insertions(+)
 create mode 100644 AI/ann_model.py
 create mode 100644 AI/dacon_seoul_ddarung.py
 create mode 100644 AI/data_shape.py
 create mode 100644 AI/evaluate_and_predict.py
 create mode 100644 AI/hyperParameter_Tuning.py
 create mode 100644 AI/indicator_with_california.py
 create mode 100644 AI/mae_and_mse.py
 create mode 100644 AI/matplotlib_plot2.py
 create mode 100644 AI/matplotlib_scatter_and_plot.py
 create mode 100644 AI/missing_value_handling.py
 create mode 100644 AI/multiLayer_Perceptron.py
 create mode 100644 AI/r2_score.py
 create mode 100644 AI/rmse_def.py
 create mode 100644 AI/split_train_test1.py
 create mode 100644 AI/split_train_test2.py
 create mode 100644 AI/split_train_test3.py
 create mode 100644 AI/useful_method_from_numpy.py
 create mode 100644 README.md

➕ git pull 명령어

origin: remote repository의 URL short name

main: main branch의 remote repository

 

 

이후, push 재 진행

$ git push -u origin main
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 520 bytes | 520.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/HJ0216/TIL.git
   5376d70..1843ac3  main -> main
branch 'main' set up to track 'origin/main'.

 

필요없는 Branch 제거

$ git push origin --delete master
To https://github.com/HJ0216/TIL.git
 - [deleted]         master

 

 

 

참고 자료

📑 fetch, 원격 저장소의 데이터를 로컬에 가져오기만 하기

📑 git push, pull (fatal: refusing to merge unrelated histories) 에러

📑 git branch 삭제

📑 git pull, push와 origin의 의미

 

728x90