AI/공부

[git] 맥에서 git 설치 및 사용방법

동하조하 2021. 5. 28. 17:24

0. homebrew 및 git 설치

https://brew.sh

 

Homebrew

The Missing Package Manager for macOS (or Linux).

brew.sh

1) 맥북 intel 칩일 경우,

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2) 맥북 m1 칩일 경우,

/bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/nrubin29/bea5aa83e8dfa91370fe83b62dad6dfa/raw/48f48f7fef21abb308e129a80b3214c2538fc611/homebrew_m1.sh)"

cf. brew 위치/버전 확인

which brew # 위치
brew --version # 버전

3) git 설치

brew install git

 

1. 초기설정

1) 깃허브 계정에서 repository 생성

✔️ 프로젝트용이라면 설명을 위해 'Add a README file' 선택 / 생성 이후에도 README 파일 추가할 수 있음

 

2) 맥에서 working directory 생성 및 진입

mkdir (directory_name)
cd (directory_name)

3) 맥에서 working directory를 깃허브에 연동하기

- 사용자 이름과 이메일 주소 등록

git config --global user.name "username"
git config --global user.email "ID@example.com"

 

- 깃 저장소 생성

git init

 

2. 작업수행

0) working directory에 remote repository 깃허브로 보낼 파일 생성/저장

1) staging area 로 보내기

git add * # 새로 생성된 모든 파일
git add (파일명) # 해당 파일

2) 파일에 대한 설명을 local repository로 보내기

git commit -m "(파일 설명)"

3) 원격으로 remote repository에 연결하기 (최초 1회만)

git remote add origin "(remote repository url)"

3-1) remote repository 이름을 깃허브에서 변경하였을 경우 

git remote set-url origin "(new url)"

4) remote repository 깃허브로 내보내기

git push -u origin master # 최초 1회만
git push # 이후에

 

매수업 때 공부한 내용이나 프로젝트를 깃허브에 올려야겠다.

오늘 공부 끝-!