잡동사니에도 사랑을

[Git] git 명령어 사용 예제(1) 본문

정리/Git정리

[Git] git 명령어 사용 예제(1)

luvforjunk 2021. 11. 9. 15:57
728x90
반응형

[21.11.09] git

 

 

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d
$ git --version
git version 2.33.0.windows.1

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d
$ git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.name=luvforjunk
user.email=csj3104@naver.com
init.defaultbranch=main

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d
$ mkdir git_home

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d
$ cd git_home

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home
$ ls -l
total 0

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home
$ mkdir git_repo

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home
$ cd git_repo

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo
$ git init
Initialized empty Git repository in D:/git_home/git_repo/.git/

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git status
On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main) 
$ ls -l
total 1
-rw-r--r-- 1 bitcamp 197121 106 Nov  9 15:55 HelloTest.java -- HelloTest.java파일 생성

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git add HelloTest.java   -- 관리대상자로 잡음.

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git status
On branch main

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   HelloTest.java -- commit

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git commit -m "First Commit"
[main (root-commit) 3b7972e] First Commit
 1 file changed, 5 insertions(+)
 create mode 100644 HelloTest.java -- 메시지와 함께 commit 시켜줌

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git status
On branch main
nothing to commit, working tree clean --commit할 파일이 없음을 확인할 수 있다

 

 

 

commit을 바로 해주는 법

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ cat HelloTest.java
class HelloTest{
        public static void main(String[] args) {
                System.out.println("Hello git!!!");
        }
}

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git add HelloTest.java

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git commit -m "HelloTest.java 수정"
[main c1d9e08] HelloTest.java 수정
 1 file changed, 1 insertion(+), 1 deletion(-)

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git status
On branch main
nothing to commit, working tree clean

 

 

 

가지치기 (협업 작업할 때는 main을 건드리는 것이 아닌 가지치기한 branch에서 작업한다.)

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git branch
* main

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git branch test1 -- 가지인 test1을 만든다

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git branch
* main
  test1 -- main을 기준으로 가지인 test1이 만들어졌음을 알 수 있다.

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ ls -l
total 1  
-rw-r--r-- 1 bitcamp 197121 107 Nov  9 16:05 HelloTest.java

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git checkout test1
Switched to branch 'test1'

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (test1)
$ git branch
  main
* test1 -- main에서 test1으로 바뀌었음을 알 수 있다

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (test1)
$ vi index.html

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (test1)
$ cat index.html
Hi~~

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (test1)
$ git add index.html
warning: LF will be replaced by CRLF in index.html.
The file will have its original line endings in your working directory

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (test1)
$ git commit -m "index.html 등록"
[test1 9b48728] index.html 등록
 1 file changed, 1 insertion(+)
 create mode 100644 index.html

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (test1)
$ git status
On branch test1
nothing to commit, working tree clean

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (test1)
$ ls -l
total 2
-rw-r--r-- 1 bitcamp 197121 107 Nov  9 16:05 HelloTest.java
-rw-r--r-- 1 bitcamp 197121   5 Nov  9 16:18 index.html

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (test1)
$ ll
total 2
-rw-r--r-- 1 bitcamp 197121 107 Nov  9 16:05 HelloTest.java
-rw-r--r-- 1 bitcamp 197121   5 Nov  9 16:18 index.html

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (test1)
$ git checkout main
Switched to branch 'main'

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ ll
total 1
-rw-r--r-- 1 bitcamp 197121 107 Nov  9 16:05 HelloTest.java

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git merge test1 -- 병합시키기
Updating c1d9e08..9b48728
Fast-forward
 index.html | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 index.html
 
 bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ ll
total 2
-rw-r--r-- 1 bitcamp 197121 107 Nov  9 16:05 HelloTest.java
-rw-r--r-- 1 bitcamp 197121   6 Nov  9 16:36 index.html

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git branch -d test1
Deleted branch test1 (was 9b48728).

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_repo (main)
$ git branch
* main

 

 

 

git_tutorial 이라는 이름의 레퍼지토리를 생성하고 주소를 복사한 뒤 git bash로 돌아와 명령어를 작성한다.

 

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home
$ git clone https://github.com/luvforjunk/git_tutorial.git -- clone 붙이기
Cloning into 'git_tutorial'...
warning: You appear to have cloned an empty repository.

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home
$ ll -- 확인
total 0
drwxr-xr-x 1 bitcamp 197121 0 Nov  9 16:36 git_repo/
drwxr-xr-x 1 bitcamp 197121 0 Nov  9 17:12 git_tutorial/

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home
$ cd git_tutorial/

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_tutorial (main)
$ echo "GitHub 연결" >> README.md

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_tutorial (main)
$ ll
total 1
-rw-r--r-- 1 bitcamp 197121 14 Nov  9 17:14 README.md

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_tutorial (main)
$ git init -- 굳이 써주지 않아도 괜찮다
Reinitialized existing Git repository in D:/git_home/git_tutorial/.git/

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_tutorial (main)
$ git add README.md
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_tutorial (main)
$ git commit -m "첫번째커밋" -- 메시지와 함께 커밋시키기
[main (root-commit) 02ab287] 첫번째커밋
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

bitcamp@DESKTOP-6C6JPQJ MINGW64 /d/git_home/git_tutorial (main)
$ git push -u origin main
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 242 bytes | 242.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/luvforjunk/git_tutorial.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

 

 

728x90
반응형

'정리 > Git정리' 카테고리의 다른 글

[Git] git 명령어 사용 예제(2)  (0) 2021.11.10