Guide to Git Commands
Git is a powerful π οΈ version control system that helps developers π©βπ» manage and track π changes to their codebase. Whether you are a π beginner or an experienced π§βπ» developer, understanding essential Git commands is crucial for collaboration π€ and efficient development.
In this blog, weβll explore key Git commands with interactive explanations π§© and practical examples. Letβs dive πββοΈ in!
1. Setting Up Git
Before you start π using Git, you need to configure your user π€ information:
# Set your name git config --global user.name "Your Name" # Set your email git config --global user.email "youremail@example.com"
Why it matters:
These settings identify π€ you as the author of changes π in your commits.


2. Initializing a Git Repository
To start tracking π€οΈ a project with Git, initialize it as a repository π:
# Initialize a Git repository in your project folder git init
Example:
cd my-project git init
This creates a hidden π΅οΈ .git folder in your project, signaling that itβs now a Git repository.
3. Checking the Status of Your Repository
To view π the current state of your repository:
git status
π€ Interactive Tip:
Run this command frequently to see which files π are staged, modified βοΈ, or untracked.


4. Adding Files to the Staging Area
Before committing, you need to stage changes π:
# Add specific files git add filename # Add all files git add .
Example:
git add index.html
This stages the index.html file for the next π€οΈ commit.
5. Committing Changes
Commit your staged changes π with a message π¬:
git commit -m "Your commit message"
β Best Practice:
Write βοΈ clear and concise commit messages to describe what the changes π do.


6. Viewing Commit History
To see π a log π of all commits:
git log
Example:
git log --oneline
This shows a compact summary π of your commit history.
7. Cloning a Repository
To copy π an existing repository to your local machine π₯οΈ:
git clone repository_url
Example:
git clone https://github.com/user/repository.git
This creates a local copy π of the remote π repository.


8. Pushing Changes to a Remote Repository
To upload π€ your commits to a remote π repository:
git push origin branch_name
Example:
git push origin main
This pushes changes to the main branch of the remote repository.
9. Pulling Changes from a Remote Repository
To update π your local repository with changes from the remote:
git pull origin branch_name
Example:
git pull origin main
This merges remote changes into your local branch πΏ.


10. Creating and Switching Branches
Branches πΏ allow you to work on new features independently:
# Create a new branch git branch branch_name # Switch to a branch git checkout branch_name # Create and switch in one step git checkout -b branch_name
Example:
git checkout -b feature-login
This creates and switches to the feature-login branch πΏ.
11. Merging Branches
To merge changes from one branch πΏ into another:
git merge branch_name
Example:
git merge feature-login
This merges the feature-login branch πΏ into the current branch.


12. Resolving Merge Conflicts
Conflicts βοΈ occur when changes overlap. Git marks the conflict areas in your files π:
# After resolving conflicts, add the resolved files git add filename # Commit the resolution git commit -m "Resolved merge conflict"
π‘ Tip:
Carefully review π conflicting changes to ensure nothing important is lost.
13. Stashing Changes
To temporarily save πΎ changes without committing:
git stash
To apply stashed changes later π:
git stash apply


14. Viewing Differences Between Commits
To see π what has changed between commits:
git diff
Example:
git diff HEAD~1 HEAD
This compares π the latest commit with the one before it.

π Conclusion
Devops Multi cloud Training
Choose the training style that fits your schedule β Self-Paced or Live Interactive Sessions. Both include hands-on projects, expert support, and lifetime access.
| Feature | Self-Paced Training | Live Training |
|---|---|---|
| π― Mode | π₯Pre-Recorded Session | π§βπ«Live Class + Recordings |
| πΌ Projects | π Weekend Real-Time Projects | π Weekdays + Weekend Real-Time Projects |
| β Doubt Clearing | π Weekend Live Support Session | π§ Anytime Doubt Clearing Session |
| π₯ Career Support & Mentorship | β No | β Yes |
| π Global Certification Training | β No | β Yes |
| π Access | βΎοΈ Lifetime Access | βΎοΈ Lifetime Access |
| π° Fees | βΉ4,999 (2 x βΉ2,500) | βΉ7,999 (2 x βΉ4,000) |
| βΉοΈ For More Info | Explore Self-Paced Training | Explore Live Training |
