0%

Git guideline


Understanding Git Basics

Working Directory

This is where you actually edit files on your local machine.

Staging Area (Index)

A buffer between your working directory and the repository.
You decide what exactly goes into the next commit.

Repository

The database that stores all commit history.

Typical workflow:

1
Working Directory → Staging Area → Local Repository → Remote Repository

Once this flow makes sense, Git becomes much easier.

Essential Git Commands

Initial Setup

1
2
3
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global --list

Initialize a repository:

1
git init

Cloning a Repository

1
2
# HTTPS
git clone https://github.com/username/repo.git

SSH (recommended)

1
git clone git@github.com:username/repo.git

Tracking and Committing Changes

1
2
3
git status
git add .
git commit -m "feat: add login feature"

View history

1
git log --oneline
  • feat: new feature
  • fix: bug fix
  • docs: documentation
  • refactor: refactoring

Working with Remote Repositories

1
2
3
4
git remote add origin <repo-url>
git remote -v
git push origin main
git pull origin main

Avoid force push unless you know exactly what you’re doing:

1
git push --force-with-lease

Branching and Merging

Branches allow safe experimentation.

1
2
3
4
5
git branch
git checkout -b feature/login
git checkout main
git merge feature/login
git branch -d feature/login
  • main – stable production
  • feature/* – new features
  • hotfix/* – urgent fixes

Undoing Changes and Recovery

Git is powerful because almost nothing is truly lost.

1
2
3
4
5
git reset --soft <commit>
git reset --mixed <commit>
git reset --hard <commit>
git reflog
git reflog is your emergency exit.

Tags and Version Releases

1
2
git tag -a v1.0 -m "First release"
git push origin --tags

Tags are ideal for marking stable releases.

Common Development Scenarios

New Project Push

1
2
3
4
5
git init
git add .
git commit -m "init: initial commit"
git remote add origin <repo>
git push -u origin main

Team Feature Development

1
2
3
git checkout -b feature/payment
git commit -m "feat: payment integration"
git push origin feature/payment

Hotfix Production Bug

1
2
3
4
git checkout main
git pull
git checkout -b hotfix/critical-bug
git commit -m "fix: critical production issue"

Common Pitfalls and How to Avoid Them

  • Forgot git add
  • Merge conflicts ignored
  • Panic after git reset –hard
  • Using password instead of token/SSH

Tip: If something goes wrong, stop and check git reflog.

1
2
3
ssh-keygen -t ed25519 -C "you@example.com"
cat ~/.ssh/id_ed25519.pub
ssh -T git@github.com

Successful output:

1
Hi username! You've successfully authenticated.

Git Best Practices

Commit small, meaningful changes

Write clear commit messages

Use branches aggressively

Clean unused branches regularly

Prefer SSH over HTTPS

Use fine-grained tokens for automation

Conclusion

You don’t need to memorize every Git command.

Git is not about commands—it’s about understanding history and collaboration.

Once you understand the workflow, Git becomes a powerful safety net rather than a source of anxiety.