git start ( real 처음부터 )

Bellao·2022년 1월 23일
0
post-thumbnail

GIT 은 소스 관리용도 또는 소스 공유 및 협업목적으로 많이 쓰이고 있다.
매번 설치해보고 깔짝 깔짝 거렸는데, 다시 새롭게 제대로 알고 써보자

> 먼저 GITHUP SIGNUP

https://github.com/

> GIT INSTALL

[root@svr01 centos]# yum install git

> GIT SETUP

[root@svr01 centos]# git config --global user.name "name"
[root@svr01 centos]# git config --global user.email name@gmail.com
  • git config --list에서는 user,name과 user.email만 제대로 등록됬는지 확인하면 된다.
[root@svr01 centos]# git config --list
user.name=name
user.email=name@gmail.com

> GIT NEW TOKEN

> GITHUP new repository 생성

  • 소스공유 편하도록 public 으로 생성

> git으로 업로드


[root@svr01 centos]# git init
Initialized empty Git repository in /home/centos/.git/
[root@svr01 centos]# git add .
  • 버전1 버전2처럼 파일에 대한 버전정보를 남기는데 쓰이는게 commit
[root@svr01 work]# git commit -m "first commit"
[master (root-commit) d7c524a] first commit
 175 files changed, 720247 insertions(+)
 create mode 100644 .bash_history
 create mode 100644 .bash_logout
 create mode 100644 .bash_profile
:

[root@svr01 work]# git branch -M main
  • 어떤 repogitory로 보낼지 셋업해준다.
[root@svr01 work]# git remote add origin https://github.com/name/proj01.git
[root@svr01 work]# git push -u origin main
Username for 'https://github.com': name
Password for 'https://name@github.com': 
Counting objects: 257, done.
Compressing objects: 100% (200/200), done.
Writing objects: 100% (257/257), 2.00 MiB | 1.26 MiB/s, done.
Total 257 (delta 131), reused 0 (delta 0)
remote: Resolving deltas: 100% (131/131), done.
To https://github.com/name/proj01.git
 * [new branch]      main -> main
Branch main set up to track remote branch main from origin.

[root@svr01 work]# git remote -v
origin  https://github.com/name/proj01.git (fetch)
origin  https://github.com/name/proj01.git (push)
  • 여기까지하면 githup에 해당 repogitory에 파일 확인

> 반대로 githup에 있는 registory 파일들을 다운로드

git clone https://github.com/name/proj01.git newfolder

branch

앞서 협업을 하기 위해 git을 많이 사용하다고 했는데,
협업을 위해 독립적으로 개발자들이 소스를 수정하고, 합칠 수 있게 해주는 개념이 branch이다.
dfault branch 는 main 이고
main 외에 새로운 branch를 만들고, 각 branch의 내용을 merge할 수 있다.

> 여기서 새로운 branch 생성해서 업로드

git add .
git status
git commit -m "clone new commit"
git checkout -b branch01
git push -u origin branch01
  • 새로운 branch 내용을 올리고 main에 반영하기 위해 pull request
  • "compare & pull request"를 통해 새로운 branch의 내용 확인
  • Yes - merge pull request ( 새로운 내용을 main 에 반영 )
  • No - review change ( 새로운 내용의 수정이 필요한 경우 재요청 )
git push -u origin main

> 변경된 소스를 다시 다운받고 업로드 하는 명령어

git add. 
git commit -m " second commit"
git pull origint master
git push origin master

기억해야 할 것

  • push 코드를 올리고 pull 다운받고 !!!
  • commit으로 버전에 대한 히스토리 기록
  • branch로 각 코드들을 수정 관리하고 main 에 merge 할수 있다.
profile
MySQL DBA

0개의 댓글