-
Notifications
You must be signed in to change notification settings - Fork 1
Git Guide
Git is a powerful version control system that has become an essential tool in modern software development. Whether you're working on a personal project or collaborating with a large team, Git enables efficient code management, seamless collaboration, and a structured workflow.
Git is a distributed version control system that tracks changes in your codebase, allowing developers to manage project history efficiently. Unlike traditional version control systems, Git offers:
- Full project history stored locally for easy access
- Offline development, with the ability to sync changes later
- Powerful branching and merging, enabling parallel development
- Enhanced security, ensuring the integrity of every commit
Git is widely adopted because it provides:
- Collaboration: Multiple developers can work on the same project without conflicts
- Version Tracking: Every change is recorded, making it easy to review, compare, and revert
- Backup & Recovery: Your code history is stored both locally and remotely
- Branching Flexibility: Experiment with new features without disrupting the main codebase
- Security: Cryptographic commit tracking ensures data integrity
This guide will take you through Git’s fundamental concepts, key commands, and best practices, helping you master version control for smoother and more efficient development. 🚀
Git was created by Linus Torvalds in 2005 to help manage the development of the Linux kernel. Before Git, the Linux development community relied on proprietary tools, which posed issues related to licensing and collaboration. Torvalds designed Git to be fast, distributed, and highly efficient, allowing developers to track and merge changes seamlessly.
- 2005: Git is created by Linus Torvalds for Linux development.
- 2008: GitHub launches, providing a platform for open-source collaboration.
- 2011: Git becomes widely adopted across industries beyond open-source projects.
- 2013: Microsoft starts using Git internally for development.
- 2018: Microsoft acquires GitHub, reinforcing Git’s dominance in software development.
- Present: Git remains the industry standard for version control, used by developers and teams worldwide.
With Git, developers can maintain version history, collaborate on shared code, and efficiently manage software projects.
-
🔧 Git Was Created by Linus Torvalds
Git was developed in 2005 by Linus Torvalds, the creator of Linux, after a dispute with BitKeeper, a previous version control system used by the Linux kernel team. -
🌍 "Git" Has a Humble Meaning
Linus Torvalds humorously named Git after the British slang term "git", which means "an unpleasant person." He described it as "the stupid content tracker." -
⚡ The Fastest Version Control System
Git can handle millions of lines of code efficiently. Major companies like Google, Microsoft, and Facebook use Git for large-scale projects. -
🚀 GitHub Wasn't Always Around
GitHub, the most famous Git hosting platform, was founded in 2008, three years after Git was created. -
🕒 The Longest Commit in Git History
A commit in the Linux kernel repository took 3.5 hours to push due to its enormous size! -
👀 You Can Time Travel in Git
Usinggit reflog
, you can restore deleted commits even if they were accidentally removed. -
🎭 April Fools' Day Prank in GitHub
GitHub once played a prank where every user's contribution graph turned into a 3D perspective view on April 1st. -
🐙 The Five-Armed Octocat
GitHub’s mascot is an Octocat—a cat with five octopus-like arms! -
📈 Over 420 Million Repositories
The platform hosts more than 420 million Git repositories created by developers worldwide!
Check if Git is installed:
git --version
If Git is not installed, download it:
- Windows: Git for Windows
-
Mac: Install via Homebrew
brew install git
-
Linux: Install via package manager
sudo apt install git # Debian-based sudo yum install git # Red Hat-based
Set up your username and email (important for commits):
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Verify configuration:
git config --list
Command | Description | Example |
---|---|---|
git log --oneline |
Displays a compact commit history | git log --oneline |
git stash |
Temporarily saves uncommitted changes | git stash |
git stash show |
Shows the changes stored in the most recent stash | git stash show |
git stash pop |
Restores the most recent stashed changes and removes them from the stash | git stash pop |
gcm |
Shortcut for git checkout main (or git checkout master , depending on the repo) |
gcm |
gl |
Shortcut for git pull (alias) |
gl |
gp |
Shortcut for git push (alias) |
gp |
git checkout - |
Checkout the previous commit or branch | git checkout - |
git status |
Shows the status of changes in the working directory | git status |
git diff |
Displays differences between the working directory and the last commit | git diff |
git diff --staged |
Shows differences between staged files and the last commit | git diff --staged |
git add <file> |
Stages a specific file for commit | git add filename.txt |
git add . |
Stages all changes in the working directory | git add . |
git commit -m "message" |
Commits staged changes with a message | git commit -m "Fix bug" |
git commit --amend |
Modifies the last commit (changes message or adds files) | git commit --amend |
git clone <repo_url> |
Clones a repository to your local machine | git clone https://github.com/user/repo.git |
git branch |
Lists all branches in the repository | git branch |
git checkout <branch> |
Switches to a different branch | git checkout feature-branch |
git merge <branch> |
Merges a specified branch into the current branch | git merge develop |
git rebase <branch> |
Applies commits from one branch onto another | git rebase main |
git branch feature-branch
Switch to the new branch:
git checkout feature-branch
Shortcut (create + switch in one command):
git checkout -b feature-branch
After merging, remove the branch:
git branch -d feature-branch
git checkout main
git merge feature-branch
- Git marks conflicts in the affected files.
- Manually resolve the conflicts in the code.
- Add the resolved files:
git add filename
- Complete the merge:
git commit -m "Resolved merge conflicts"
To move feature branch commits on top of main
:
git checkout feature-branch
git rebase main
If conflicts occur, resolve them, then continue:
git rebase --continue
If you made a commit but want to undo it while keeping the changes in your working directory (i.e., your files aren't lost), use the following command:
git reset --soft HEAD~1
- HEAD~1: Refers to the previous commit (one commit before the current one).
- This command uncommits the last commit, but keeps the changes staged for commit. It's like you didn't commit yet, but your changes are ready to be committed again.
If you want to completely remove the last commit and discard any changes you made, use this command:
git reset --hard HEAD~1
- --hard: This option will reset both your staging area and working directory, discarding all changes in the last commit.
- Be cautious with this command, as any changes made in the last commit will be lost completely.
If you want to undo a specific commit (not necessarily the last one), and create a new commit that undoes it, use:
git revert commit-hash
- commit-hash: The hash of the commit you want to revert. (i.e f80e1af)
- This command doesn't remove the commit from the history but creates a new commit that reverses the changes made in the specified commit.
- It’s useful when you need to "undo" a commit in a way that’s visible in the commit history, preserving the integrity of your version control.
While working locally, you might use some files in your working directory that you don't want to stage (like object files, executables, .env
files with passwords in it, etc.). You can make git
not see those files by putting their names into files with .gitignore
extension.
Examples:
# files with .o extension (sub-directories are also affected)
*.o
# don't ignore foo.o
!foo.o
# ignore only in this directory (don't ignore in sub-directories)
# for example if there exists another bar.out in a sub-folder named b, b/bar.out will be staged but ./bar.out won't.
/bar.out
Important!: Make sure to append file names that has sensitive information (like passwords) to .gitignore, or while staging exclude them yourself.
✔ Write Meaningful Commit Messages
Example:
✅ "Fixed login issue in user authentication"
❌ "Update file"
✔ Pull Before You Push
Always pull the latest changes before pushing new commits:
git pull origin main
✔ Use Branches for Features & Fixes
Always work on a separate feature branch:
git checkout -b feature-new-ui
✔ Write Good Pull Requests
- Clearly explain what the changes do.
- Attach screenshots if needed.
- Assign reviewers before merging.
📖 Official Git Documentation: https://git-scm.com/doc
📖 GitHub Documentation: https://docs.github.com/en
📖 Git Cheatsheet (PDF): https://education.github.com/git-cheat-sheet-education.pdf
1️⃣ Review this guide and apply these Git practices.
2️⃣ Each team member should add at least one additional Git topic or tip.
- Celil Özkan (Backend)
- Cem Sarpkaya (Backend)
- Özgür Savaşçıoğlu (Backend)
- Ahmet Hacıoğlu (Frontend)
- Ahmet Selçuk Ersoy (Frontend)
- Bahadır Demirel (Frontend)
- Muhammed Ekinci (Frontend)
- Ali Gökçek (Mobile)
- Seyit Mustafa Demir (Mobile)
- Meeting Agenda 1
- Meeting Agenda 2
- Meeting Agenda 3
- Meeting Agenda 4
- Meeting Agenda 5
- Meeting Agenda 6
- Meeting Notes 1 (16.02.2025)
- Meeting Notes 2 (24.02.2025)
- Meeting Notes 3 (27.02.2025)
- Meeting Notes 4 (04.03.2025)
- Meeting Notes 5 (06.03.2025)
- Meeting Notes 6 (13.03.2025)
- Meeting Notes 7 (17.03.2025)
- Meeting Notes 8 (21.04.2025)
- Meeting Notes 9 (28.04.2025)
- Meeting Notes 10 (01.05.2025)
- Meeting Notes 11 (06.05.2025)
- Lecture Notes 1 (13.02.2025)
- Lecture Notes 2 (20.02.2025)
- Lecture Notes 3 (27.02.2025)
- Lecture Notes 4 (06.03.2025)
- Lecture Notes 5 (13.03.2025)
Click to Expand ⬇️
- Scenario 1 - User Register
- Scenario 2 - Dietitian Register
- Scenario 3 - User Login
- Scenario 4 - User Deletion
- Scenario 5 - Upload & Edit Recipe
- Scenario 6 - Single Meal Planning
- Scenario 7 - Grocery Price Comparison
- Scenario 8 - Community Forum
- Scenario 9 - Recipe Discovery & Filter
- Scenario 10 - Local Food Discovery
- Scenario 11 - Nutritional Guidance Interaction
- Scenario 12 - Market Inventory Management
- Scenario 13 - Profile Management and Preference Settings
- Scenario 14 - Rate and Comment the Recipe by User
- Scenario 15 - Bookmark a Meal and Access it in Profile Page
- Scenario 16 - Adding Nutrition Tips to a Dietitian Profile
- Scenario 17 - User Forget Password
- Scenario 18 ‐ User Follows Unfollows Users
- Scenario 19 - Allergen Alert and Meal Plan Adjustment
- Scenario 20 - Dietitian Rating of a Recipe