월. 8월 4th, 2025

Introduction

Git is the industry-standard version control system for tracking code changes and collaborating on projects. Whether you’re a developer, sysadmin, or hobbyist, mastering Git on Linux unlocks efficient workflow management. This guide covers installation, configuration, and essential commands with practical examples.


Step 1: Installing Git

For Debian/Ubuntu (apt)

sudo apt update && sudo apt install git -y  

For Fedora/RHEL (dnf)

sudo dnf install git -y  

For Arch/Manjaro (pacman)

sudo pacman -Sy git  

Verify Installation:

git --version  
# Example output: git version 2.34.1  

Step 2: First-Time Configuration

Set your global identity (used in all commits):

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

Optional Settings:

git config --global core.editor "nano"  # Set default text editor  
git config --global init.defaultBranch main  # Change default branch name  

View Settings:

git config --list  

Step 3: Basic Git Workflow

A. Initialize a Repository

mkdir my-project && cd my-project  
git init  # Creates hidden .git directory  

B. Track Files

echo "Hello Git!" > README.md  
git add README.md         # Stage specific file  
git add .                 # Stage all changes  

C. Commit Changes

git commit -m "Add README file"  

D. Check Status & History

git status        # View unstaged/staged changes  
git log --oneline # View commit history  

Step 4: Remote Repositories (GitHub/GitLab)

A. Link to Remote

git remote add origin https://github.com/username/repo.git  

B. Push Changes

git push -u origin main  # First push (sets upstream)  
git push                 # Subsequent pushes  

C. Pull Updates

git pull origin main  

Step 5: Essential Commands Cheat Sheet

Command Description
git diff Show unstaged changes
git reset HEAD~1 Undo last commit (keep changes)
git checkout -- Discard local changes
git clone Download existing repository
git branch Create new branch

Troubleshooting Tips

  1. Permission Denied?
    Use sudo only for installation, not daily Git operations.

  2. Authentication Issues:
    Use SSH keys instead of HTTPS:

    git remote set-url origin git@github.com:username/repo.git  
  3. Merge Conflicts:
    Resolve conflicts in marked files, then run:

    git add . && git commit -m "Resolved conflicts"  

Conclusion

Git transforms chaotic development into a streamlined process. Start with small projects, commit frequently, and explore advanced features like branching (git branch) and stashing (git stash). Practice daily to build confidence!

Pro Tip: Run git help for instant documentation (e.g., git help commit).

> Next Steps: Learn about .gitignore files, branching strategies, and interactive rebasing. Happy version controlling! 🐧💻

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다