728x90

Introduction

In a professional setting, terms like Git, Merge, and Commit are commonly used when working with source code. While I’ve been using Git intuitively, handling errors has been a challenge. So, I’ve decided to take this opportunity to study what Git is and how to use it effectively.

1. What is Git?

Git is a version control system (VCS) designed to efficiently manage source code. It was created by Linus Torvalds, the developer of Linux, and is now widely used for managing software development projects beyond just Linux.

Git’s core functionalities can be categorized into three main areas:

1) Version Control

Git helps track changes in files over time, allowing developers to see who modified what and when. This makes it easy to revert changes and maintain a history of the project.

2) Backup

Git allows users to store a copy of their project on a different machine or server for safety and accessibility.

Some common backup locations include:

  • External storage (USB drives, external hard drives)
  • Cloud services (Dropbox, Google Drive)
  • Remote repositories (GitHub, GitLab, Bitbucket)

3) Collaboration

With Git, multiple developers can work on the same project simultaneously. By using a remote repository, team members can easily share and merge changes without conflicts.

2. How to Install Git (Windows)

To start using Git, you need to install it on your PC. Since Git uses Linux commands, installing Git on Windows also includes Git Bash, a command-line interface for executing Git commands.

Step 1: Download and Install Git

  1. Go to the official Git website: https://git-scm.com/.
  2. Click "Download for Windows".
  3. If the download doesn’t start automatically, click "Click Here to Download"
    .
  4. Run the downloaded file and proceed with the installation using the default settings.

Step 2: Launch Git

  1. Open the Windows Start Menu.
  2. Search for Git Bash and click to launch it.
  3. A terminal window will appear, ready for Git commands.

Step 3: Configure Git

Before using Git, you need to set up your user information, which will be recorded in each commit.

Run the following commands in Git Bash:

# Register user information
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

# Verify registered user information
git config --get user.name
git config --get user.email

This setup ensures that your commits are properly attributed to you.

Conclusion

Git is an essential tool for managing source code, enabling version control, backup, and collaboration. Learning how to use Git effectively can greatly improve your workflow and efficiency in software development.

References

Thank you for reading! I hope this guide helps you get started with Git. 🚀

728x90
728x90

 

항상 git branch를 관리하다보면 개발중인 코드를 dev 또는 master에 merge를 해야되는 경우가 생긴다.

 

이럴 때 항상 헷갈리는 것이 바로 "어떤 브랜치를 남겨놓고 어떤 브랜치가 사라질 것인가?" 이다. 

 

대다수의 사람들이 위와 같은 궁금증으로 git merge에 대해 검색할 것이라고 생각한다.

 

이 참에 해당 내용에 대해 정리하고자 한다.

 

 

기본적으로 우리는 만들어진 각 브랜치에서 작업을 하다가 완료가 되는 시점이 오면 브랜치 작업을 마무리 하고 기존 브랜치에 합쳐야 한다. 이 과정을 바로 "git merge" 브랜치 병합이라고 한다.

 

아래 그림과 같이 master branch에 dev branch를 병합해야 한다면 

 

즉, master브랜치를 남기고, dev브랜치를 없애려면

 

다음과 같이 진행하면된다.

 

git checkout master #먼저 남길 branch로 이동한다.

git merge dev # master branch에 dev브랜치를 merge한다.

#큰 이상이 없으면 vim이 실행되고, 자동으로 commit이 생성된다. 그러면 esc버튼을 누르고 'wq'입력!

git log # log를 확인하면 merge가 된것을 확인할 수 있다.

 

 

 

 

728x90
728x90

 지난 시간까지 git의 버전 관리하는 방법에 대해 알아보았습니다. 이번 시간부터는 git에서 용도에 따라 버전을 구분 지어주는 branch에 대해 알아보도록 하겠습니다. 

 

1. git branch


① git branch란?

git branch란 나뭇가지처럼 기존의 기능을 유지하면서 용도에 따라 신규기능을 추가하고 싶을 때 해당 git을 여러 갈래로 나눠주는 것을 이야기합니다. 추후에는 나눠진 가지를 다시 합쳐주는 것도 가능하고요. 

② git branch를 만드는 방법 (git branch)

git branch를 만드는 방법은 다음과 같습니다. 

git branch <만드려는 branch 이름>

만들어진 branch를 확인하는 방법은 

git branch

 

③ git branch를 이동하는 방법 (git checkout)

그럼 기능 추가를 위해 branch를 이동하는 방법에 대해 말씀드리겠습니다. 

git branch checkout <목적 branch>

이동을 하게되면 git의 head가 목적 branch로 변경된 것을 볼 수 있습니다. 

 

이번 시간에는 branch의 기본 개념과 사용방법에 대해 알아보았습니다. branch는 동료들과 협업을 진행할 때 매우 필요한 작업으로 반드시 알아두어야 합니다. 다음 시간에는 정말 중요한 merge기능에 대해 알아보도록 하겠습니다. 

 

추가적으로 궁금하신 사항 있으면 댓글로 남겨주세요 :) 

 

*Reference

- "지옥에서 온 문서 관리자 깃&깃허브 입문" 이지스버블리싱 - 이고요, 고경희 지음

 

 

부족한 글이지만 읽어주셔서 감사합니다. 

728x90
728x90

 이전 시간에 git reset에 대해 학습했었죠. git reset <커밋 해시>는 해당 해시로 버전을 이동하면서 해당 버전 이후에 만들어진 버전들은 모두 삭제한다는 점이 가장 큰 특징이었는데요. 추가로 --hard 옵션을 추가해야 Working Tree에 있는 파일들까지 해당 커밋 버전에 맞게 변경된다는 점을 꼭 기억하셔야 됩니다. 이번 시간에는 커밋 정보를 삭제하지 않고 이전 버전으로 돌아가는 git revert 명령어에 대해 알아보겠습니다. 

 

 

1. git revert


 git revert 명령어는 취소하려는 커밋 해시를 지정해주고 해당 커밋 해시를 취소하게 됩니다. git reset 뒤에 지정하는 커밋 해시로 돌아가는 것과는 다르죠. git revert는 취소하려는 커밋 해시를 지정하면 해당 커밋 해시를 취소하였다는 커밋을 새롭게 만들어 줍니다.(취소한 버전을 새롭게 만든다는 게 git revert의 커밋 취소 원리입니다. ) 쉽게 말해 취소한 이력을 버전을 만들어 기록하는 것이죠.

 

그럼 이제부터 git revert 사용 방법에 대해 예시를 통해 알려 드리도록 하겠습니다. 

먼저 git log를 통해 현재 커밋들을 확인합니다. 

 $ git log --oneline --graph

그리고, 취소하려는 커밋을 확인합니다. (저는 a 커밋을 취소하겠습니다.)

$ git revert f2e779b

 그러면 중간에 아래와 같이 해당 커밋을 취소하며 변경된 사항과 그 내용을 담은 커밋을 생성하게 됩니다. 해당 내용들을 확인하고 이상이 없으면 ":"를 누르고 "wq"를 통해 저장해주면 해당 커밋을 취소한 새로운 커밋이 생성되게 됩니다. 

남들과 협업을 하게 될 때 git을 사용하게 되는 경우가 있는데 만약 취소나 변경사항이 생길 경우 git reset을 사용하는 것보다 git revert를 사용하는 것이 훨씬 안정적이므로 꼭 까먹지 않았으면 좋겠습니다. 

 

 

 

*Reference

- "지옥에서 온 문서 관리자 깃&깃허브 입문" 이지스버블리싱 - 이고요, 고경희 지음

-

-

 

부족한 글이지만 읽어주셔서 감사합니다. 

 

728x90

+ Recent posts