티스토리 뷰

Programming/Git&Bash

[Git] git 명령어

RosyPark 2020. 3. 1. 17:32
  • 설치환경 - 윈도우 
  • 터미널 열기 - 윈도우 창에서 Git Bash Here 

# git 기본

git init => git 시작하기(폴더에서 사용) 

 

git add * 
git commit -m "message" => git commit  - 만들기 

git log => git log 보기

 

git log // -->  후 commit 9708a9e87454197d885f9cc402d1e6bd60432137 라는 숫자가 나옴

이때 앞글자 7자리만 따서

git checkout 9708a9e => 원하는 시점으로 돌아가기

git checkout => 최신커밋으로 돌리기 

 

 

 

git remote add origin https://~~~  => 원격 github 저장소와 연결하기

 

git push origin master  => git push

git pull origin master  => git pull 

 

---------------------

# git branch 확인하기

- branch를 써야하는 이유

1. 버젼관리를 할 수 있음

2. 작업하고 있는 소스는 그대로 두면서 커스텀된 기능을 추가할 수 있다는 장점

 

 

git checkout <branch> 

=> 원하는 branch로 변경 

 

git checkout -b <new branch> <enter>
=> 현재 브랜치의 저장소에 있는 내용을 복사하여 새로운 브렌치를 만들고
=> 작업브렌치를 변경하여 작업영역으로 복사된 새로운 브렌치의 내용을 복사해온다.

git branch <enter> => 현재 작업영역의 브렌치 이름을 확인한다.

*현재 디렉토리에서 파일작업을 한다, 파일수정을 한다.

git add <파일이름> <enter>
git commit -m <커밋 메시지> <enter>
git log <enter> => 커밋 기록을 확인한다.
git branch < enter> => 브렌치를 확인한다.


git branch -d <비 작업영역의 삭제하고자 하는 브렌치이름> <enter> =>branch를 삭제한다.
=>error, ex2 is not fully merged. run git branch -D <branc>

git branch -D <비 작업영역의 삭제하고자 하는 브렌치이름> <enter> =>branch를 삭제한다.

git branch <enter> => branch가 삭제되었는지 확인한다.

 

 

git branch <enter> => 저장소안의 branch 정보를 보여줌, *표가 현재 branch임.
*master => 처음 자동으로 생성한 브렌치는 무조건 마스터 브렌치임

git branch <new_branch name> <enter> =>현재 브렌치 내용을 새로운 브렌치로 복사한다. 단 저장소 내에서
git branch <enter> =>새로 복제된 브렌치를 포함하여 저장소안의 전체 브렌치 정보를 보여준다.
=>*가 표기된 브렌치가 현재 작업영역과 연결된 브렌치이다.

git checkout <branch name> <enter>
=> 저장소에서 작업영역으로 브렌치내용을 복사해온다.
=> 작업영역에서 기존에 브렌치에 저장된 파일은 삭제된다.
=> 새로운 브렌치에서 작업해야할 경우에사용한다.

작업영역에서 파일을 수정한다.
git add <수정된 파일이름> <enter>
git commit -m "커밋 메시지" <enter> 작업영여의 내용을 저장영역의 브렌치에 저장한다

 

git stash

git pull

git stash pop => git pull 충돌시

 

 

# git (end)

- 'q' 키보드 누르기 

 

 

# default editor

  1. press "i"
  2. write your merge message
  3. press "esc"
  4. write ":wq"
  5. then press enter

 

# Tutorial

1. <나의 repository> 오류 없이 내 local에서 수정하고 싶다 (천천히 따라하기) - 

git clone https://github.com/~~~/gittest.git (repository address)
cd gittest
echo "test" >> README.md
git add * 
git status
git commit -m "---"
git push origin master // 현재 master branch를 사용하고 있기 때문에! 

 

2.  <나의 repository> 나의 repository에서 branch를 만들고 싶을 때! 

git branch  // branch가 무엇이 있는 지 확인, 기본적으로 master이 있음 
git checkout -b new_branch // 현재 branch에 있는 내용을 그대로 new_branch에 복사하기
git branch
git push -u origin new_branch // branch에 있는 내용을 remote repository에 push

 

나의 repository에서 branch를 만들고 싶을 때! 

 

remote repository에 두개의 branch가 생긴다  

 

 

 

3. 남의 repository에 fork한 후 

- 남의 repository = upstream

-  fork한 나의 repository = origin 

 

fork한 respository 복사하기

git clone https://github.com/..... /gittest.git

cd gittest

git branch // 이때 남의 repository의 master branch밖에 없음

 

git remote -v

=> origin  https://github.com/.../gittest.git (fetch)
=> origin  https://github.com/..../gittest.git (push)

 

git remote add upstream https://github.com/..../gittest.git  // 남의 repository와 나의 local과 연결 필요

=> origin  https://github.com/.../gittest.git (fetch)
=> origin  https://github.com/.../gittest.git (push)
=> upstream        https://github.com/;;;;;;/gittest.git (fetch)
=> upstream        https://github.com/;;;;;;/gittest.git (push)

 

git branch new_branch2

git checkout new_branch2 

 

git push origin new_branch2 // new_branch2에ㅐ 해당하는 branch를 자신의 원격 repository로 복사 

 

 

남의 repository의 새로운 커밋이 있다면 동기화하기

git pull upstream master 

 

 

4. 

git remote add upstream https://github.com/..../gittest.git  // 연결후 

git remote -v

git fetch upstream

git branch -va

git checkout master

git merge upstream/master

 

git push origin [branch name] # branch name에 해당하는 branch를 자신의 원격 저장소에 푸시

 

 

 

 

5. 기타

git config --list
git config user.name
git config user.email


git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

 

 

 

6. --------------------------  

git checkout issue20
git status
git add *
git commit -m "---" 
git push origin issue20 

 

 

----

원저장소에서 받다가 에러 난겨우?

원래는

git pull upstream master

----

에러난경우?

git stash

git stash list

git pull upstream master

https://nesoy.github.io/articles/2017-03/Git-Stash

 

 

 

출처

1. https://opentutorials.org/module/2676/15260

 

branch 만들기 - 지옥에서 온 Git

수업소개 branch를 만드는 방법에 대해서 알아봅니다.  수업  수업에서 사용한 명령어 브랜치의 목록을 볼 때 git branch 브랜치를 생성할 때  git branch "새로운 브랜치 이름" 브랜치를 삭제할 때 git branch -d 병합하지 않은 브랜치를 강제 삭제할 때  git branch -D 브랜치를 전환(체크아웃)할 때 git checkout "전환하려는 브랜치 이름" 브랜치를 생성하고 전환까지 할 때  git checkout -b "생성

opentutorials.org

2. https://gmlwjd9405.github.io/2017/10/28/how-to-collaborate-on-GitHub-2.html

 

[GitHub] GitHub로 협업하는 방법[2] - Forking Workflow - Heee's Development Blog

Step by step goes a long way.

gmlwjd9405.github.io

 

'Programming > Git&Bash' 카테고리의 다른 글

[Git] 원하는 commit만 들고오기  (0) 2020.12.03
[Git] opensource 기여하기  (0) 2020.08.14
[Git] git, SourceTree, Bitbucket 설치와 설명  (0) 2020.03.01
우분투 github 사용방법  (0) 2019.12.31
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함