티스토리 뷰

기타

git과 git hub 사용하기

코딩계란 2024. 1. 19. 17:53
728x90

git, github

git: 소스 코드 버전 관리를 위한 tool

git hub, git lab: git을 활용할 수 있는 웹 사이트 

 

기본 용어 

repository: 하나의 큰 저장소, 기본 단위

branch: repository에 만드는 작은 저장소 - 실제 저장 단위

origin: 최초의 코드 

remote: git hub이나 git lab같은 원격 저장소 

commit: 변경 내용을 적용

push: 로컬의 내용을 remote에 업로드 

pull, fetch: remote의 내용을 로컬에 반영

clone: branch의 내용을 로컬로 가져오는 것

merge: 변경한 내용을 하나로 합치는 것

 

git hub, git 시작 및 설정 

git hub 가입

 

GitHub: Let’s build from here

GitHub is where over 100 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and fea...

github.com

위 링크로 들어가 회원 가입 진행. 

 

Git Hub Desktop 설치 

 

GitHub Desktop

Simple collaboration from your desktop

desktop.github.com

 


git 다운로드 

window 버전

 

Git - Downloading Package

Download for Windows Click here to download the latest (2.43.0) 32-bit version of Git for Windows. This is the most recent maintained build. It was released about 2 months ago, on 2023-11-20. Other Git for Windows downloads Standalone Installer 32-bit Git

git-scm.com

MAC

brew install git

 

리눅스

sudo apt-get update
sudo apt-get install git

 

설치 확인

git --version

Branch

브랜치 이름 변경

git의 기본 브랜치 이름을 main으로 변경. git의 기본 branch명은 master이고 github은 main이기 때문에 변경할 필요가 있다. 

git config --global init.defaultBranch main

브랜치 이름 확인

git branch

 

브랜치 생성

git checkout -b 브랜치이름


브랜치 전환

git checkout 브랜치이름

git 이메일과 이름 설정

git config --global user.name 사용자명
git config --global user.email 이메일

 

이메일과 이름 확인 

git config --list

 

 

Git, GitHub

현재 디렉토리의 내용을 git에 저장

현재 디렉토리를 로컬 git에 등록

git init

로컬 디렉토리 안에서 .git 디렉토리 삭제 

window

rmdir .git

그 외

rm -rf .git

git에 파일을 등록

git add 파일 or 디렉토리 이름
git add. (현재 디렉토리의 모든 내용을 git에 등록)

 

로컬 git에 업로드

git commit -m "메시지"

 

현재까지 commit한 기록 확인 

git log

 

이전 작업으로 돌아가기 

git reset --soft commit 
git reset --hard commit

--soft commit: 이전 내역을 저장해놓지만 코드 수정은 하지 않는다. 

--hard commit: 이전 내용을 지우고 코드를 수정한다. 


Github 원격 저장

.gitignore 파일(업로드 하지 않을 디렉토리나 파일을 등록)을 만들어서 가상환경 디렉토리를 등록해서 업로드가 안되도록 한다. 

 

패키지 목록 저장(아래 글 참조)

 

[python] 가상 환경 만들기(windows)

가상 환경 생성 python -m venv 가상환경명 위 명령어로 가상 환경을 생성할 수 있다. VScode로 실행할 경우 가상환경 폴더가 생성된 것을 확인 가능. 이후 생성한 폴더로 현재 디렉토리를 변경한다. cd

growingegg.tistory.com

 

1. github에 접속해서 repository 생성

2. 로컬 git과 원격 repository를 연결

git remote add 이름 레포지토리url

 

맨 처음 연결하는 경우는 origin을 사용한다. 

git remote add origin 레포지토리url

예시

git remote add origin https://github.com/JangBogwang/mystudy

 

연결확인

git remote -v

 

3. 현재 commit을 업로드

git push 이름 브랜치이름

예시

git push origin main

* 주의 처음 업로드할 때 repository에 파일이 있을 경우(ex.readme.md) 업로드가 되지 않을 수도 있다. 

git에 업로드된 것을 확인할 수 있다.

 

* github에서 수정한 내용 가져오기

git pull 이름 브랜치명

github의 프로젝트 가져오기 

gir clone 저장소url

 

728x90