Git is a distributed version control system used by developers to track changes in source code during software development. It allows multiple people to collaborate, manage code versions, and revert to previous stages if needed.
What Git Does
-
Tracks changes in your files
-
Allows collaboration on code with others
-
Maintains a history of code updates
-
Helps manage different versions (branches) of your project
Key Concepts
Term | Meaning |
---|---|
Repository (repo) | A project folder tracked by Git |
Commit | A snapshot of your code changes |
Branch | A separate line of development |
Merge | Combining changes from different branches |
Clone | Copying a repository to your local system |
Push/Pull | Upload/download changes to/from remote repo (e.g., GitHub) |
Git Installation
Step 1: Install Git
-
Windows/Mac/Linux: Download from https://git-scm.com/
Step 2: Set up your identity
Sample Git Tutorial
Let’s go through a simple example using Git on your local machine.
Step 1: Create a Project Directory
Step 2: Initialize Git
This creates a hidden .git
folder that tracks changes.
Step 3: Create a File
Step 4: Check File Status
Step 5: Add File to Staging Area
Step 6: Commit the Change
Step 7: Create a New Branch (Optional)
Step 8: Make Changes and Commit
Step 9: Merge Changes to Main
Step 10: View Commit History
Push to GitHub (Optional)
If you want to store your project on GitHub:
Step 1: Create a repo on GitHub
Step 2: Link local repo to GitHub
Summary
Command | Description |
---|---|
git init | Start a new Git repository |
git status | Check current repo state |
git add <file> | Stage file for commit |
git commit -m "msg" | Save a snapshot |
git branch | View branches |
git checkout -b <name> | Create and switch to a branch |
git merge <branch> | Merge another branch |
git log | View commit history |
git push | Send code to remote repo |