git & github

LILO Ghim·2021년 11월 10일
0

git & github

개념 이해가 정말 어려웠던 git, 실질적으로 project에서 활용해보지 않아서 인지 그림이 그려지지 않아서 힘들었는데, 일단 명령어 기준으로 정리해둔다.

1) GitHub

Git repository를 위한 호스팅 플랫폼
로컬 프로젝트 repository를 원격 클라우드 기반 GitHub 저장소로 업로드 할 수 있고, public repository들을 통해 다른 개발자들과 교류

GitHub repository는 모든 프로젝트 파일들과 코드의 히스토리를 관리 할 수 있게 해주고, public 혹은 private 하게 협업할 수 있게 해준다

2) Git

버전 관리 시스템으로, 시간이 지남에 따라 파일의 변경사항을 추적하는 도구


||| start : 반드시 작업중인 directory 내에서 시작할 것!

git --version

버전확인

git config --global user.name "name"
git config --global user.email "email"

git에 본인정보 등록

mkdir "git_practice"

디렉토리 생성

cd "git_practice"

디렉토리 이동

git init

깃 시작

.gitignore 생성

python, pycharm, VisualStudioCode, vim, macOS, Linux, zsh 키워드를 추가하여 create

cd "프로젝트 폴더명"
touch .gitignore
vi .gitignore

###
gitignore.io #결과 전체 복사
###

#가장 하단에 아래 내용 추가
my_settings.py

git add .

git status

깃 상태 확인

(commits yet)

||| commit : 특정 시간의 코드 스냅샷의 형태로 해당 repository의 커밋 기록이 남는다

git commit -m "message"

커밋하기

git log

commit history 확인

git checkout <commit-hash>

git log 에서 보이는 커밋의 실제 hash값으로 작성
특정 커밋 시점의 코드로 되돌리고 싶은 경우

||| git hub : local directory와 git hub의 directory의 연동

<Github repo 생성> : github site -> New repository

||| upload

git remote add origin "repository address"

이 주소를 orgin으로 부르기로 함

git push -u orgin master

코드를 업로드 함

||| branch : 기본 브랜치는 master 또는 main
이 시점에서 격리해서 작업을 하고 싶다 또는 브랜치를 딴다고 함
나만의 공간을 떼어서 작업을 하고 다시 합친다
기본 브랜치는 master 또는 main


git branch <new-branch-name>

새로운 브랜치 생성하고 작업

git checkout <new-branch-name>

다른 브랜치로 이동

git checkout -b <new-branch-name>

브랜치 생성과 동시에 생성된 브랜치로 이동

git merge <new-branch-name>

A라는 브랜치에서 작업한 내용을 B라는 브랜치에 적용하고 싶을 때

git checkout -d <new-branch-name>

브랜치 삭제

지워야 하는 파일 삭제

github의 repository에 올리면 안되는 파일을 올렸을 경우,
예를 들어 gitignore 되지 않은 경우, 파일을 삭제 할 때 아래와 같이 진행한다
git checkout main				#해당 branch로 이동
git rm --cached -r "file_name."			#지워야 하는 파일 삭제
git commit -m "file_name."			#commit
git push -u origin main				#push

참고

pwd
cd desktop

현재 위치 확인 후  > desktop 이동

cd ~

홈디렉토리 이동

cd "folder_name"

폴더로 이동

mkdir "git_practice"

디렉토리 생성

cd "git_practice"

디렉토리 이동

ls -al

디렉토리 내 파일 보기

touch lilo.md

본인 영문이름 파일 생성

vi lilo.md

해당 파일에서 본인 이름 작성 후 저장

cat lilo.md

내용 확인
profile
킴릴로

0개의 댓글