본문 바로가기

Git

Git (Distributed Version Control Systems)

  1. Git 이란 무엇인가? 
    • 버전 관리 시스템이다.   기능 개선 등 버그 수정등 의미 있는 변화들을 기록 하고 추적한다. 주로, 소프트웨어 개발에서 사용을 하지만, 공동 집필등 다양한 작업자들과 함께 협업 툴로도 사용이 가능하다.
    • 우리는 이미 버전 관리 시스템을 사용을 하고 있다. 대표적으로 , Wikipedia와 Sharepoint Portal을 들수 있고, 여기서 작업한 내역을 버전으로 관리를 하면서 필요 시 이전 작업 한 내용으로 돌아갈 수 있다. 
  2. 왜 Git을 사용하는가? 
    • Version Control System (VCS) : Git을 통해서 여러 명의 개발자가 동시에 프로젝트를 진행을 할수 있으며, 쉽게 변경 사항에 대해서 파악을 할 수 있다. 
    • Branch and Merge : Branch를 생성을 하면 현 Main(master)에 영향을 주지 않고, 개선 작업이나 변경 작업을 진행을 할 수 있다. Branch를 생성을 하는 건 다른 소스코드의 복사본을 만들어서 작업을 하는 것이다. 작업 이 완료가 되면, 이 해당 변경에 대해서 main으로 Merge(통합)을 하거나 아니면 필요가 없다면 해당 branch를 삭제를 할 수 있다. 
  3. 어떻게 Git을 사용하는가? 
    1. 설치 :
      • 우선, Git ( https://git-scm.com/download/win )을 다운 받아서 설치를 하면 , Local Repository를 구성해서 Git을 command 로 사용이 가능하다.
      • GUI 형태가 편하거나 Git를 처음 사용을 하는 경우에는 Git UI client 를 설치하면 되고, 대표적인 GIT UI Client로 Source Tree이 있으며, 아래 링크를 통해서 다운 받아서 설치하면 된다. 
      • Local Repository로 구성을 할 경우에 컴퓨터에 문제가 발생을 하면 모든 데이터가 날라갈 수 있다. 최소한 Google Drive나 Dropbox에 백업을 받는 것이 좋다.
      • 또한, 혼자 하는 개발이 아닌, 협업을 통해서 진행을 하는 경우에 Remote Repository 를 사용을 해야 한다. 대표적인 Online Git Platform은 GitHub, GitLab , buitbucket 등이 있다.
    2. Git Diagram
      1. Git Remote Repository 사용하는 경우 : 

        • branch
    3. Best Practice 
      • 반드시 작업 이전에 Pull Request을 해서 Remote Repository에서 최신의 코드를 받고 변경작업 및 Commit를 진행을 하고, 다시 Pull 을 해서 충돌이 있는지 확인을 하고, Push를 해야 한다. 이를 통해서 발생할 수 있는 충돌을 최소화할 수 있다.  
    4. 유용한 Git Command 
      • You can always refer to the official Git documentation for more details and options for each command.
        1. git init: Initializes a new Git repository, creating a .git subfolder in the project's root directory.
          git init​
           
        2. git status: Shows the status of changes as untracked, modified, or staged.
          git status​
        3. git add: Adds changes in the working directory to the staging area.
          git add <file(s)>​
        4. git commit: Records changes in the repository, creating a new commit.
          git commit -m "Commit message"​
        5. git log: Displays a log of commits, showing the commit history.
          git log​

        6. git diff: Shows the differences between the working directory, staging area, and the last commit.
          git diff​
        7. git clone: Creates a copy of a remote repository on your local machine.
          git clone <repository_url>​
        8. git checkout: Switches to a different branch
          git checkout <branch_name>​
        9. git branch: Lists existing branches and allows you to create new branches
          git branch git branch <branch_name>​
        10. git merge: Combines changes from different branches
          git merge <branch_name>​
        11. git pull: Fetches changes from a remote repository and merges them into the current branch.
          git pull origin <branch_name>​
        12. git push: Pushes local changes to a remote repository
          git push origin <branch_name>​
        13. git remote: Shows a list of remote repositories.
          git remote -v​
        14. git fetch: Fetches changes from a remote repository without merging.
          git fetch origin​
        15. git reset: Unstages changes in the staging area.
          git reset <file(s)>​
        16. git rm: Removes files from both the working directory and the Git repository.
          git rm <file(s)>​

 

Git is a distributed version control system (VCS) that is widely used for tracking changes in source code during software development. It was created by Linus Torvalds in 2005 to manage the development of the Linux kernel, but it has since become the standard for version control in many other projects.

Here are some key concepts and features of Git:

  • Version Control System (VCS): Git allows multiple developers to work on a project simultaneously without interfering with each other. It tracks changes made to files over time so that you can recall specific versions later.
  • Distributed System: Unlike centralized version control systems, each developer's working copy of the code is a complete repository with its own history. This means that if a central server goes down, developers can continue to work independently.
  • Branching and Merging: Git provides powerful branching and merging capabilities, allowing developers to create separate branches for different features or bug fixes. Branches can be easily merged, facilitating collaboration and parallel development.
  • Snapshots, Not Differences: Git doesn't store data as a series of file-based changesets. Instead, it records changes as a series of snapshots of the project over time. This approach provides efficiency and speed.
  • GitHub and GitLab: Platforms like GitHub and GitLab are web-based hosting services that utilize Git for version control. They offer additional collaboration features, issue tracking, and more, making it easier for teams to work together.
  • Commit: A commit is a snapshot of the project at a specific point in time. Each commit has a unique identifier and includes changes made to files.
  • Clone: Creating a copy of a repository on your local machine is called cloning. This allows you to work on your own version of the project.

Pull and Push: Pulling retrieves changes from a remote repository to your local machine, while pushing sends your changes to a remote repository. This enables collaboration among team members