Youโ€™re the Expert!

pynfinity

git

Git

Your complete recipe for mastering Git โ€” course modules & quick-reference guide in one place.

VC Recipe Module 3 sections

BASICS

Initialize a New Git Repository

Explore the concepts and examples below to master this topic.

Code Example
# Initialize a new repository
git init

# Check the status of the repository
git status
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Checking the Status of Your Files

Explore the concepts and examples below to master this topic.

Code Example
# Check the status of the repository
git status

# Show changes in the working directory
git diff
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Adding Files to the Staging Area

Explore the concepts and examples below to master this topic.

Code Example
# Add a single file to the staging area
git add filename.txt

# Add all files to the staging area
git add .
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Committing Changes

Explore the concepts and examples below to master this topic.

Code Example
# Commit staged changes
git commit -m "Initial commit"

# View commit history
git log
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Cloning a Repository

Explore the concepts and examples below to master this topic.

Code Example
# Clone an existing repository
git clone https://github.com/username/repository.git
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Checking the Commit History

Explore the concepts and examples below to master this topic.

Code Example
# View the commit history in the repository
git log

# View the commit history with a specific format
git log --oneline
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

INTERMEDIATE

Creating and Switching Branches

Explore the concepts and examples below to master this topic.

Code Example
# Create a new branch
git branch new-branch

# Switch to the new branch
git checkout new-branch

# Alternatively, create and switch in one command
git checkout -b new-branch
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Merging Branches

Explore the concepts and examples below to master this topic.

Code Example
# Switch to the branch you want to merge into
git checkout main

# Merge another branch into the current branch
git merge new-branch

# Resolve conflicts, if any
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Deleting Branches

Explore the concepts and examples below to master this topic.

Code Example
# Delete a local branch
git branch -d new-branch

# Delete a remote branch
git push origin --delete new-branch
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Stashing Changes

Explore the concepts and examples below to master this topic.

Code Example
# Stash changes that are not yet committed
git stash

# List all stashes
git stash list

# Apply the latest stash
git stash apply
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Working with Remote Repositories

Explore the concepts and examples below to master this topic.

Code Example
# Add a remote repository
git remote add origin https://github.com/username/repository.git

# Push changes to the remote repository
git push origin main

# Pull changes from the remote repository
git pull origin main

# Check remote repository URLs
git remote -v
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Undoing Changes

Explore the concepts and examples below to master this topic.

Code Example
# Undo changes in the working directory (before commit)
git checkout -- filename.txt

# Undo the last commit (keep the changes staged)
git reset --soft HEAD~1

# Undo the last commit (remove changes)
git reset --hard HEAD~1
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

ADVANCED

Rebasing Branches

Explore the concepts and examples below to master this topic.

Code Example
# Rebase a branch onto another branch
git checkout feature-branch
git rebase main

# Resolve conflicts if they occur during the rebase
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Cherry-picking Commits

Explore the concepts and examples below to master this topic.

Code Example
# Apply a specific commit from another branch
git cherry-pick <commit-hash>

# After cherry-pick, commit if necessary
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Tagging Releases

Explore the concepts and examples below to master this topic.

Code Example
# Create a new tag
git tag v1.0

# Push tags to the remote repository
git push origin v1.0

# List all tags
git tag

# Checkout a specific tag
git checkout v1.0
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Resetting and Reverting Commits

Explore the concepts and examples below to master this topic.

Code Example
# Reset to a specific commit (and delete changes)
git reset --hard <commit-hash>

# Revert a commit (create a new commit that undoes the changes)
git revert <commit-hash>
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Resolving Merge Conflicts

Explore the concepts and examples below to master this topic.

Code Example
# After a merge conflict, Git will mark the conflicting files
git status

# Open the conflicting file and manually resolve conflicts
# After resolving, stage the file and commit the merge
git add filename.txt
git commit
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.

Squashing Commits

Explore the concepts and examples below to master this topic.

Code Example
# Combine multiple commits into one (during rebase)
git rebase -i HEAD~3

# Mark the commits you want to squash
# Change 'pick' to 'squash' for the commits to combine

# After finishing, you'll have one commit containing all the changes
Video Walkthrough
Coming soon โ€” in-depth video explanation for this topic.
โšก Quick Reference โ€” Recipe

Use the reference cards below for fast lookup. Perfect for brushing up on syntax while you cook your code. ๐Ÿณ

Initialize a New Git Repository
# Initialize a new repository
git init

# Check the status of the repository
git status
Checking the Status of Your Files
# Check the status of the repository
git status

# Show changes in the working directory
git diff
Adding Files to the Staging Area
# Add a single file to the staging area
git add filename.txt

# Add all files to the staging area
git add .
Committing Changes
# Commit staged changes
git commit -m "Initial commit"

# View commit history
git log
Cloning a Repository
# Clone an existing repository
git clone https://github.com/username/repository.git
Checking the Commit History
# View the commit history in the repository
git log

# View the commit history with a specific format
git log --oneline

Creating and Switching Branches
# Create a new branch
git branch new-branch

# Switch to the new branch
git checkout new-branch

# Alternatively, create and switch in one command
git checkout -b new-branch
Merging Branches
# Switch to the branch you want to merge into
git checkout main

# Merge another branch into the current branch
git merge new-branch

# Resolve conflicts, if any
Deleting Branches
# Delete a local branch
git branch -d new-branch

# Delete a remote branch
git push origin --delete new-branch
Stashing Changes
# Stash changes that are not yet committed
git stash

# List all stashes
git stash list

# Apply the latest stash
git stash apply
Working with Remote Repositories
# Add a remote repository
git remote add origin https://github.com/username/repository.git

# Push changes to the remote repository
git push origin main

# Pull changes from the remote repository
git pull origin main

# Check remote repository URLs
git remote -v
Undoing Changes
# Undo changes in the working directory (before commit)
git checkout -- filename.txt

# Undo the last commit (keep the changes staged)
git reset --soft HEAD~1

# Undo the last commit (remove changes)
git reset --hard HEAD~1

Rebasing Branches
# Rebase a branch onto another branch
git checkout feature-branch
git rebase main

# Resolve conflicts if they occur during the rebase
Cherry-picking Commits
# Apply a specific commit from another branch
git cherry-pick <commit-hash>

# After cherry-pick, commit if necessary
Tagging Releases
# Create a new tag
git tag v1.0

# Push tags to the remote repository
git push origin v1.0

# List all tags
git tag

# Checkout a specific tag
git checkout v1.0
Resetting and Reverting Commits
# Reset to a specific commit (and delete changes)
git reset --hard <commit-hash>

# Revert a commit (create a new commit that undoes the changes)
git revert <commit-hash>
Resolving Merge Conflicts
# After a merge conflict, Git will mark the conflicting files
git status

# Open the conflicting file and manually resolve conflicts
# After resolving, stage the file and commit the merge
git add filename.txt
git commit
Squashing Commits
# Combine multiple commits into one (during rebase)
git rebase -i HEAD~3

# Mark the commits you want to squash
# Change 'pick' to 'squash' for the commits to combine

# After finishing, you'll have one commit containing all the changes

Recipe Complete! ๐ŸŽ‰

You've explored the full Git recipe.
Keep practising โ€” a language a day keeps AI away! ๐Ÿค–

Back to VC Courses


Pynfinity
Install Pynfinity Add to home screen for the best experience