0726[git]

망지·2022년 7월 26일
1
post-custom-banner

📌 git

📙 git 설치

✔️git 홈페이지에서 64-bit 용 설치

✔️ 설치과정중 아래 체크만 체크하고 나머지 다 default로 설치진행.

📙 git bash 실행

r2com@DESKTOP-DD3FU43 MINGW64 ~
$ mkdir git-test && cd $_

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test
$ echo "Hello World" > README.txt

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test
$ cat README.txt
Hello World

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test
$

📙 git hub

✔️ github 로그인 - 리포지디토리 - new

✔️이름 : test-dev - 생성

📙 git bash -git init

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test
$ git init
Initialized empty Git repository in C:/Users/r2com/git-test/.git/

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ ls
README.txt

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ ls -al
total 21
drwxr-xr-x 1 r2com 197121  0 Jul 26 09:35 ./
drwxr-xr-x 1 r2com 197121  0 Jul 26 09:33 ../
drwxr-xr-x 1 r2com 197121  0 Jul 26 09:35 .git/ ## init 통해 생성
-rw-r--r-- 1 r2com 197121 12 Jul 26 09:33 README.txt


r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git config --global user.name "mangji"
warning: user.name has multiple values
error: cannot overwrite multiple values with a single value
       Use a regexp, --add or --replace-all to change user.name.

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git config --global user.email "test@example.com"
warning: user.email has multiple values
error: cannot overwrite multiple values with a single value
       Use a regexp, --add or --replace-all to change user.email.



r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git add README.txt
warning: in the working copy of 'README.txt', LF will be replaced by CRLF the next time Git touches it

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git commit -m "add-site" ## 작업한 내용 남기기 

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ echo "Aloha" >> README.txt

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ cat README>txt
cat: README: No such file or directory

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git add README.txt
warning: in the working copy of 'README.txt', LF will be replaced by CRLF the next time Git touches it

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git commit -m "add update"
[master ed57f25] add update
 1 file changed, 1 insertion(+)

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git log
commit ed57f25df216e78723744459346790b20d143fcf (HEAD -> master)
Author: == <==>
Date:   Tue Jul 26 09:47:22 2022 +0900

    add update

commit 4bf982a466fbfdcc96da593dd928117fbbd39bb2
Author: == <==>
Date:   Tue Jul 26 09:42:19 2022 +0900

    add-site

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ cat README.txt
Hello World
Aloha

📙 git bash - rollback

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git checkout 4bf982a466fbfdcc96da593dd928117fbbd39bb2

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test ((4bf982a...))
$ cat README.txt
Hello World

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test ((4bf982a...)) ## 다시 가장 최근 버전으로
$ git checkout -
Previous HEAD position was 4bf982a add-site
Switched to branch 'master'

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ cat README.txt
Hello World
Aloha

📙 git bash - git hub에 올리기

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git remote add origin https://github.com/mangjini/test-dev.git

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git push origin master

https://github.com/settings/profile
맨 하단 developer settings - personal access tokens - generate new token
note : test-dev
repo체크

generate token

token 복사해서 붙여넣고 sign in

sign in 하면 push 됨.

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git push origin master
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 409 bytes | 409.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/mangjini/test-dev.git
 * [new branch]      master -> master

github 리포지토리에서 확인 가능해짐.

📙 내려받기

r2com@DESKTOP-DD3FU43 MINGW64 ~
$ git clone https://github.com/mangjini/test-dev.git
Cloning into 'test-dev'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0
Receiving objects: 100% (6/6), done.
r2com@DESKTOP-DD3FU43 MINGW64 ~
$ cd test-dev

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-dev (master)
$ ls
README.txt

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-dev (master)
$ cat README.txt
Hello World
Aloha

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-dev (master)
$ echo "NIHAO" >> README.txt

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-dev (master)
$ git add .
warning: in the working copy of 'README.txt', LF will be replaced by CRLF the next time Git touches it

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-dev (master)
$ git commit -m "add list"
[master 2c55c2d] add list
 1 file changed, 1 insertion(+)

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-dev (master)
$ git push origin master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 243 bytes | 243.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/mangjini/test-dev.git
   ed57f25..2c55c2d  master -> master

다른사용자 (git-test[A])가 확인하기

r2com@DESKTOP-DD3FU43 MINGW64 ~
$ cd git-test

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ cat README.txt
Hello World
Aloha


r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git pull origin master ## 니하오 추가된 것 가져오기.
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 223 bytes | 13.00 KiB/s, done.
From https://github.com/mangjini/test-dev
 * branch            master     -> FETCH_HEAD
   ed57f25..2c55c2d  master     -> origin/master
Updating ed57f25..2c55c2d
Fast-forward
 README.txt | 1 +
 1 file changed, 1 insertion(+)
 
 r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ cat README.txt
Hello World
Aloha
NIHAO

📙정리(삭제)

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git rm README.txt
rm 'README.txt'

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git commit -m "remove README.txt"
[master 5dd0c11] remove README.txt
 1 file changed, 3 deletions(-)
 delete mode 100644 README.txt
 
 r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (2/2), 182 bytes | 182.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/mangjini/test-dev.git
   2c55c2d..5dd0c11  master -> master

삭제 확인

📙 git lab

✔️centos7 버츄얼 박스에 올리기

서버 IP : 192.168.4.211 -> mobaxterm으로 진입, 아래 명령어 실행 ( gitlab 설치)

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
EXTERNAL_URL="http://192.168.4.211" yum install -y gitlab-ce

✔️gitlab설치 완료되면 웹브라우저에서 ip 로 접근 가능.

✔️아래 명령어 통해서 패스워드 확인하고 로그인 하기.

cat /etc/gitlab/initial_root_password # 패스워드 수정

✔️패스워드 변경하기

✔️ 사용자 만들기
root에서 로그아웃 - register now

✔️사용자 승인하기
root로 로그인 - 메뉴

✔️ 사용자 로그인
root 로그아웃하고 생성해둔 사용자로 로그인, role은 그냥 설문조사 편하게 기입.

✔️ 프로젝트 생성

📙 a사용자(centos),b사용자(win) 협업

a사용자-local

[root@localhost ~]# yum install git -y
[root@localhost ~]# mkdir git-test && cd $_
[root@localhost git-test]# ls -al
total 0
drwxr-xr-x  2 root root   6 Jul 26 12:05 .
dr-xr-x---. 4 root root 163 Jul 26 12:05 ..
[root@localhost git-test]# echo "Hello World" > README.txt

[root@localhost git-test]# git init
Initialized empty Git repository in /root/git-test/.git/

[root@localhost git-test]# git config --global user.email "test@example.com"
[root@localhost git-test]# git config --global user.name "mangji"
[root@localhost git-test]# git add README.txt
[root@localhost git-test]# git commit -m "add site"
[root@localhost git-test]# echo "Aloha" >> README.txt
[root@localhost git-test]# git add README.txt

[root@localhost git-test]# git commit -m "add update"

 
[root@localhost git-test]# git log
commit bf8dc53a40f2557c7b559c4fd6569c269d3a13f2
Author: mangji <test@example.com>
Date:   Tue Jul 26 12:13:41 2022 +0900

    add update

commit db621ebd231d5c8fcc38d81e55626cd447a9cc8f
Author: mangji <test@example.com>
Date:   Tue Jul 26 12:11:17 2022 +0900

    add site

[root@localhost git-test]# cat README.txt
Hello World
Aloha

[root@localhost git-test]# git checkout db621e ## 앞에 5글자정도만 해도 체크아웃 가능.


[root@localhost git-test]# cat README.txt
Hello World

[root@localhost git-test]# git checkout - #가장 최신버전으로 원복

[root@localhost git-test]# cat README.txt
Hello World
Aloha

✔️local에서 벗어나 원격 저장소 이용하기

1) protection 설정

2) 명령어 진행

[root@localhost git-test]# git remote add origin http://192.168.4.211/kmj/test-procject.git

[root@localhost git-test]# git branch -M main

[root@localhost git-test]# git push -uf origin main

✔️ B사용자

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ cd ~

r2com@DESKTOP-DD3FU43 MINGW64 ~
$ git clone http://192.168.4.211/kmj/test-procject.git
Cloning into 'test-procject'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (6/6), done.

r2com@DESKTOP-DD3FU43 MINGW64 ~
$ cd test-procject/

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-procject (main)
$ ls
README.txt

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-procject (main)
$ cat README.txt
Hello World
Aloha

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-procject (main)
$ echo "NIHAO" >> README.txt

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-procject (main)
$ git add README.txt
warning: in the working copy of 'README.txt', LF will be replaced by CRLF the next time Git touches it

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-procject (main)
$ git commit -m "add list"
[main ff5bd3b] add list
 1 file changed, 1 insertion(+)

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-procject (main)
$ git branch -M main

r2com@DESKTOP-DD3FU43 MINGW64 ~/test-procject (main)
$ git push -uf origin main

a 사용자


[root@localhost git-test]# cat README.txt
Hello World
Aloha

[root@localhost git-test]# git pull origin main

[root@localhost git-test]# cat README.txt

Hello World
Aloha
NIHAO

[root@localhost git-test]# git rm README.txt
rm 'README.txt'

[root@localhost git-test]# git commit -m "remove README.txt"
[main 28e0244] remove README.txt
 1 file changed, 3 deletions(-)
 delete mode 100644 README.txt
 
[root@localhost git-test]# git push origin main
Username for 'http://192.168.4.211': kmj
Password for 'http://kmj@192.168.4.211':
Counting objects: 3, done.
Writing objects: 100% (2/2), 196 bytes | 0 bytes/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To http://192.168.4.211/kmj/test-procject.git
   ff5bd3b..28e0244  main -> main

->삭제완료

📙✔️✏️📢⭐️📌

📌 기타

⭐️ trouble shooting

r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git push origin master
remote: Permission to mangjini/test-dev.git denied to JJ
fatal: unable to access 'https://github.com/mangjini/test-dev.git/': The requested URL returned error: 403

⭐️ 오픈소스 설치하고 자동완성기능 안될때는 exit 했다가 재진입.

[root@localhost git-test]# exit

profile
꾸준히, 차근차근
post-custom-banner

0개의 댓글