Ultimate Beginner's Guide to Mastering Git and GitHub with Cheat Sheet
Learn the Essentials of Git and GitHub with Easy-to-Follow Steps and a Handy Cheat Sheet for Quick Reference
What is Git?
Git is an open-source distributed version control system that helps developers track changes in their code over time. It allows:
Version tracking: Save and access previous versions of your code.
Collaboration: Work seamlessly with others on the same project.
Branching and merging: Experiment with new features without affecting the main codebase.
Installing Git
Download Git: Visit git-scm.com and download the version for your OS.
Install Git: Follow the installation wizard.
Verify Installation: Open your terminal or command prompt and type:
git --version
Basic Git Commands
Set up Git: Configure your username and email.
git config --global user.name "Your Name" git config --global user.email "youremail@example.com"
Initialize a repository: Start version control for a project.
git init
Check repository status: View changes in your project.
git status
Stage changes: Add changes to be committed.
git add <file_name> git add . # Add all changes
Commit changes: Save your changes with a message.
git commit -m "Your commit message"
View history: Check the history of commits.
git log
Undo changes:
- Unstage files:
git reset <file_name>
- Unstage files:
Discard changes: git checkout -- <file_name>
Step-by-Step Workflow in Chart
What is GitHub?
GitHub is a cloud-based platform that hosts Git repositories. It makes sharing and collaboration on projects easier by providing tools for:
Remote repositories: Store code online for access from anywhere.
Collaboration: Manage pull requests, issues, and contributions.
Showcasing work: Share your projects with the world.
Getting Started with GitHub
Create an account: Sign up at github.com.
Create a repository:
Go to the GitHub dashboard.
Click on New Repository and fill in the details.
Clone a repository: Download a GitHub repository to your local machine.
git clone <repository_url>
Push changes: Upload local changes to GitHub.
git remote add origin <repository_url> git branch -M main git push -u origin main
Pull changes: Sync your local repository with the remote.
git pull
Essential GitHub Features
Fork and Pull Requests:
Fork a repository to create your copy.
Make changes and submit a pull request to contribute to the original repository.
Issues: Report bugs or request features.
GitHub Pages: Host static websites directly from your repositories.
Git and GitHub Cheat Sheet
Common Git Commands
Set up Git:
git config --global user.name "Your Name" git config --global user.email "youremail@example.com"
Initialize Repository:
git init
Check Status:
git status
Add Changes:
git add <file_name> git add .
Commit Changes:
git commit -m "Your message"
View Log:
git log
Undo Changes:
git reset <file_name> git checkout -- <file_name>
Push Changes:
git push -u origin main
Pull Updates:
git pull
Essential GitHub Actions
Clone Repository:
git clone <repository_url>
Create Branch:
git branch <branch_name> git checkout <branch_name>
Merge Branch:
git merge <branch_name>
Create Pull Request: Use the GitHub interface.
Manage Issues: Track bugs or feature requests directly on GitHub.
Tips for Beginners
Use descriptive commit messages: They help others understand your changes.
Learn branching: Create separate branches for features or fixes.
git branch <branch_name> git checkout <branch_name>
Use
.gitignore
: Exclude unnecessary files from version control.Explore GitHub Docs: GitHub’s documentation is an excellent resource.