Git basic

DaBeen Yi
4 min readJul 13, 2021

--

What is Git and How to use it?

Concept and Basic flows

Git is a free and open source distributed version control system. It means with Git I can track any files that I want to check.

위의 사전적 정의에 따르면 Git은 버전 관리 시스템이라고 말할 수 있다. 하지만 실무에서는 버전 관리 시스템의 연장선인 분업화 도구로 많이 사용되고 있는 듯하다. 특히 개발자들이 하나의 프로젝트를 동시 다발적으로 진행하기 위해 Git을 이용한다는건 많이 들어봤을 것이다.

이처럼 분업 도구로써 Git의 핵심은 master와 branch라고 할 수 있다. 즉, 말 그대로 중심이 되는 master가 있고 해당 master로부터 branch 하나를 생성해서 작업을 진행하는 것이다. 아래 그림을 보면 쉽게 이해가 될 것 이다.

https://www.nobledesktop.com/learn/git/git-branches

기본틀에서 내가 하나의 branch를 생성한 다음 (branch를 ‘딴다’고 표현한다.) 해당 branch에서 내가 하고자 하는 작업을 진행한다. 그 후, 해당 branch를 master에 merge한다. 이렇게 하면 내가 작업한 내용이 master에 흡수?되는 것이다.

너무 당연한 얘기지만 master에 바로 작업하는게 아니라 branch를 따서 작업을 하는 이유는 (1)혹시 모를 ‘원본 손상’을 예방하기 위함과 (2)이력 관리 (branch 마다 작업 내용을 기입해두면 어떤 branch에서 어떤 작업을 했는지 쉽게 파악 가능) 라고 정리할 수 있다.

Initialization

Move to a directory where you want to initiate Git.

$ git init

A hidden directory named ‘.git’ is created.

All changes that are occurred on the directory are recorded on this directory.

Staging

These changes are not saved immediately. It goes through ‘Staging’ step first so that a user can choose which files are saved or not.

Check current git status with below command.

$ git status

Then you can check files which are changed/added/modified.

$ git statusNo commits yetUntracked files:
(use "git add <file>..." to include in what will be committed)
test.txt

Use git add command to add file on stage.

$ git add test.txt <-- For specific file
$ git add . <-- For all changes on a directory

Commit

A command to save your changes to the local repository.

-m option is for adding comment.

$ git commit -m "Add a new info"

여기까지가 내 local PC에서 일어나는 일이다. 만일 해당 작업을 원격지로 보내고 싶다면 아래 Push 명령어를 사용하면 된다.

Push

Push changes from local repository to the remote site.

$ git push 

Push 이후에는 Pull request 라던가 merge 그리고 delete branch 등 추가 작업을 진행 할 수 있는데 해당 내용은 내가 조금 더 정리된 후에 추가로 작성해보려고 한다. (아직은 장님이 코끼리 만지듯 알음알음 파악하고 있어서..)

🍰

--

--

No responses yet