A compact, practical guide to the most used Git and GitHub commands — ideal for beginners and a quick reference for experienced users.
- Quick Start
- Common Workflow
- Cheat Sheet (by category)
- Advanced Tips
- VSCode Tips
- Contributing
- Resources
- Contact
Install Git and configure your identity:
# install: go to https://git-scm.com for platform-specific installers
git --version
...
## ✅ Common Workflow
The typical flow for feature development:
1. Create a branch
```bash
git checkout -b feature/your-feature- Make changes, stage, and commit
git add .
git commit -m "Short, descriptive message"- Sync with remote and push
git fetch origin
git pull --rebase origin main
git push -u origin feature/your-feature- Open a PR, then delete the branch after merge
git branch -d feature/your-feature
git push origin --delete feature/your-featuregit init— initialize a repogit clone <url>— clone a remote repogit status— see working stategit add <file> | .— stage changesgit commit -m "msg"— commitgit push— push to remotegit pull— fetch & merge
git branch— list branchesgit checkout <branch>— switchgit checkout -b <branch>— create+switchgit merge <branch>— merge into currentgit rebase <base>— replay commits
git log --oneline --graph --decorate— condensed loggit show <commit>— inspect a commit
git restore <file>— discard local changesgit reset --soft HEAD~1— undo last commit (keep changes staged)git reset --hard HEAD~1— undo last commit and discard changesgit clean -f— remove untracked files
git tag <tag>— lightweight taggit tag -a <tag> -m "message"— annotated taggit stash/git stash pop— stash and restore
git remote -v— list remotesgit remote add origin <url>— add a remotegit remote set-url origin <new-url>— change remote
- Use clear, concise commit messages.
- Keep PRs small and focused.
- Rebase onto the main branch before opening a PR to keep history linear.
- Resolve conflicts locally with
git statusandgit diffto inspect changes.
Short commands for speed:
git status -s # short status
git log --oneline --graph # compact log w/graph- Try extensions: GitLens, Git Graph, and GitHub Pull Requests for better visibility.
- Use the Source Control view to stage commits and manage branches.
- Open the integrated terminal for quick git commands without leaving the editor.
To contribute:
- Fork the repository on GitHub.
- Clone your fork and create a branch for your work.
- Make changes, add tests if applicable, and commit.
- Stay in sync with upstream and rebase often:
git remote add upstream https://github.com/ORIGINAL/REPO.git
git fetch upstream
git rebase upstream/main- Push your branch to your fork and open a PR with a helpful description.
- Official Git docs: https://git-scm.com/docs
- GitHub docs: https://docs.github.com/en
- GitHub Git Cheat Sheet: https://education.github.com/git-cheat-sheet-education.pdf
Found something missing? Open an issue or a PR — contributions and suggestions are welcome!
Made with ❤️
- Quick Start
- Common Workflow
- Cheat Sheet (by category)
- Advanced Tips
- VSCode Tips
- Contributing
- Resources
- Contact
Install Git and configure your identity:
# install: go to https://git-scm.com for platform-specific installers
git --version
# configure (one-time):
git config --global user.name "Your Name"
git config --global user.email "you@example.com"Clone a repo and open it:
git clone https://github.com/<username>/<repo>.git
cd <repo>The typical flow for feature development:
- Create a branch
git checkout -b feature/your-feature- Make changes, stage, and commit
git add .
git commit -m "Short, descriptive message"- Sync with remote and push
git fetch origin
git pull --rebase origin main
git push -u origin feature/your-feature- Open a PR, then delete the branch after merge
git branch -d feature/your-feature
git push origin --delete feature/your-featuregit init— initialize a repogit clone <url>— clone a remote repogit status— see working stategit add <file> | .— stage changesgit commit -m "msg"— commitgit push— push to remotegit pull— fetch & merge
git branch— list branchesgit checkout <branch>— switchgit checkout -b <branch>— create+switchgit merge <branch>— merge into currentgit rebase <base>— replay commits
git log --oneline --graph --decorate— condensed loggit show <commit>— inspect a commit
git restore <file>— discard local changesgit reset --soft HEAD~1— undo last commit (keep changes staged)git reset --hard HEAD~1— undo last commit and discard changesgit clean -f— remove untracked files
git tag <tag>— lightweight taggit tag -a <tag> -m "message"— annotated taggit stash/git stash pop— stash and restore
git remote -v— list remotesgit remote add origin <url>— add a remotegit remote set-url origin <new-url>— change remote
- Use clear, concise commit messages.
- Keep PRs small and focused.
- Rebase onto the main branch before opening a PR to keep history linear.
- Resolve conflicts locally with
git statusandgit diffto inspect changes.
Short commands for speed:
git status -s # short status
git log --oneline --graph # compact log w/graph- Try extensions: GitLens, Git Graph, and GitHub Pull Requests for better visibility.
- Use the Source Control view to stage commits and manage branches.
- Open the integrated terminal for quick git commands without leaving the editor.
To contribute:
- Fork the repository on GitHub.
- Clone your fork and create a branch for your work.
- Make changes, add tests if applicable, and commit.
- Stay in sync with upstream and rebase often:
git remote add upstream https://github.com/ORIGINAL/REPO.git
git fetch upstream
git rebase upstream/main- Push your branch to your fork and open a PR with a helpful description.
- Official Git docs: https://git-scm.com/docs
- GitHub docs: https://docs.github.com/en
- GitHub Git Cheat Sheet: https://education.github.com/git-cheat-sheet-education.pdf
Found something missing? Open an issue or a PR — contributions and suggestions are welcome!
Made with ❤️
Made with ❤️
---
## 🎯 Cheat Sheet (by category)
### Setup & Quick Actions
- `git init` — initialize a repository
- `git clone <url>` — copy a remote repo locally
- `git status` — see current changes
- `git add <file> | .` — stage changes
- `git commit -m "message"` — commit staged changes
- `git push` — send commits to remote
- `git pull` — fetch + merge latest remote changes
### Branching & Merging
- `git branch` — list branches
- `git checkout <branch>` — switch branch
- `git checkout -b <branch>` — create+switch
- `git merge <branch>` — merge a branch into current one
- `git rebase <base>` — replay changes onto base
### History & Log
- `git log --oneline --graph --decorate` — compact visual commit log
- `git show <commit>` — show commit details
### Undoing & Cleanup
- `git restore <file>` — restore file to last commit state
- `git reset --soft HEAD~1` — undo commit (keep changes staged)
- `git reset --hard HEAD~1` — undo commit and discard changes
- `git clean -f` — remove untracked files
### Tags & Releases
- `git tag <tag>` — add a lightweight tag
- `git tag -a <tag> -m "message"` — annotated tag
- `git push origin <tag>` — push tag to remote
### Stashes
- `git stash` — stash uncommitted changes
- `git stash apply` — restore latest stash
- `git stash pop` — restore and remove stash
### Remote
- `git remote -v` — list remotes
- `git remote add origin <url>` — add remote
- `git remote set-url origin <new-url>` — change remote URL
---
## 💡 Advanced Tips & Best Practices
- Use meaningful commit messages and keep them short.
- Keep branches small and focused.
- Prefer PRs for code review and CI checks before merging.
- Use `git pull --rebase` to keep history linear when you pull.
- Resolve conflicts on a clean branch; use `git status` and `git diff` frequently.
Short commands:
```bash
git status -s # short status
git log --oneline --graph # brief log with graph
- Install useful extensions: GitLens, Git Graph.
- Use built-in Source Control to stage and commit quickly.
- Use the integrated terminal for small Git workflows.
If you want to contribute to this project or another GitHub repo:
- Fork the repository on GitHub.
- Clone your fork, create a branch for your change.
- Make changes, add tests where appropriate, and commit.
- Rebase/sync with upstream before opening a PR.
- Push your branch and open a pull request with a clear description.
Quick commands:
git clone https://github.com/YOUR-USERNAME/REPO-NAME.git
git remote add upstream https://github.com/ORIGINAL-USER/REPO-NAME.git
git fetch upstream && git rebase upstream/main- Official Git docs: https://git-scm.com/docs
- Git cheatsheet: https://education.github.com/git-cheat-sheet-education.pdf
- GitHub docs: https://docs.github.com/en
If you want to suggest improvements, open an issue or a PR. I appreciate your feedback — thanks for checking out Git Notes!
Made with ❤️
This documentation serves as a comprehensive reference for all major Git and GitHub commands, along with their descriptions and usage.
git initDescription: Initializes a new local Git repository in the current directory.
git add <file-name>
git add .Description: Adds specific files or all files in the current directory to the staging area.
git commit -m "Initial commit"Description: Saves the changes in the staging area to the local repository with a descriptive message.
git remote add origin <repository-url>Description: Links your local repository to a GitHub remote repository.
git push -u origin <branch-name>Description: Pushes the local files to the specified branch of the GitHub repository.
git clone <repository-url>Description: Downloads an existing GitHub repository to your local machine.
cd <repository-folder>Description: Moves into the cloned repository directory.
Description: Modify or create new files using any text editor (e.g., VSCode).
git statusDescription: Displays the status of changes in the working directory.
git add <file-name>
git add .Description: Stages the modified or added files for commit.
git commit -m "Descriptive commit message"Description: Saves the staged changes to the local repository with a commit message.
git pull origin <branch-name>Description: Syncs your local branch with the latest changes from the remote branch.
git push origin <branch-name>Description: Pushes the committed changes to the same branch on GitHub.
Steps:
- Edit the conflicting files to resolve merge conflicts.
- Stage and commit the resolved files:
git add <file-name>
git commit -m "Resolved merge conflict"git branch <branch-name>Description: Creates a new branch for feature development or bug fixes.
git checkout <branch-name>Description: Moves to an existing branch.
git checkout -b <branch-name>Description: Creates and switches to a new branch in one command.
git branchA compact, practical guide to the most used Git and GitHub commands — ideal for beginners and a quick reference for experienced users.
- Quick Start
- Common Workflow
- Cheat Sheet (by category)
- Advanced Tips
- VSCode Tips
- Contributing
- Resources
- Contact
Install Git and configure your identity:
# install: go to https://git-scm.com for platform-specific installers
git --version
# configure (one-time):
git config --global user.name "Your Name"
git config --global user.email "you@example.com"Clone a repo and open it:
git clone https://github.com/<username>/<repo>.git
cd <repo>The typical flow for feature development:
- Create a branch
git checkout -b feature/your-feature- Make changes, stage, and commit
git add .
git commit -m "Short, descriptive message"- Sync with remote and push
git fetch origin
git pull --rebase origin main
git push -u origin feature/your-feature- Open a PR, then delete the branch after merge
git branch -d feature/your-feature
git push origin --delete feature/your-featuregit init— initialize a repogit clone <url>— clone a remote repogit status— see working stategit add <file> | .— stage changesgit commit -m "msg"— commitgit push— push to remotegit pull— fetch & merge
git branch— list branchesgit checkout <branch>— switchgit checkout -b <branch>— create+switchgit merge <branch>— merge into currentgit rebase <base>— replay commits
git log --oneline --graph --decorate— condensed loggit show <commit>— inspect a commit
git restore <file>— discard local changesgit reset --soft HEAD~1— undo last commit (keep changes staged)git reset --hard HEAD~1— undo last commit and discard changesgit clean -f— remove untracked files
git tag <tag>— lightweight taggit tag -a <tag> -m "message"— annotated taggit stash/git stash pop— stash and restore
git remote -v— list remotesgit remote add origin <url>— add a remotegit remote set-url origin <new-url>— change remote
- Use clear, concise commit messages.
- Keep PRs small and focused.
- Rebase onto the main branch before opening a PR to keep history linear.
- Resolve conflicts locally with
git statusandgit diffto inspect changes.
Short commands for speed:
git status -s # short status
git log --oneline --graph # compact log w/graph- Try extensions: GitLens, Git Graph, and GitHub Pull Requests for better visibility.
- Use the Source Control view to stage commits and manage branches.
- Open the integrated terminal for quick git commands without leaving the editor.
To contribute:
- Fork the repository on GitHub.
- Clone your fork and create a branch for your work.
- Make changes, add tests if applicable, and commit.
- Stay in sync with upstream and rebase often:
git remote add upstream https://github.com/ORIGINAL/REPO.git
git fetch upstream
git rebase upstream/main- Push your branch to your fork and open a PR with a helpful description.
- Official Git docs: https://git-scm.com/docs
- GitHub docs: https://docs.github.com/en
- GitHub Git Cheat Sheet: https://education.github.com/git-cheat-sheet-education.pdf
Found something missing? Open an issue or a PR — contributions and suggestions are welcome!
Made with ❤️
git stash listDescription: Shows all stashed changes.
git stash drop <stash-name>Description: Deletes a specific stash.
git branch --show-currentDescription: Shows the branch you are currently working on.
Description: Add unwanted files or folders in a .gitignore file to exclude them from being tracked.
git pull --rebase origin <branch>Description: Rebases your branch with the latest changes from the remote branch.
git rebase -i HEAD~<n>Description: Combines multiple commits into one.
git clean -fDescription: Removes untracked files from the working directory.
This document serves as a quick reference to efficiently use Git and GitHub. Let me know if you need examples or further clarification on any command!
This guide explains how to contribute to GitHub projects, covering essential Git commands, workflows, and useful VS Code extensions to enhance your Git experience. It is particularly useful for contributing to open-source projects or preparing for Google Summer of Code (GSoC).
Forking creates a copy of the original repository in your GitHub account, allowing you to work independently.
- Go to the GitHub repository you want to contribute to.
- Click the Fork button (top right corner).
- Your forked repository will now appear under your GitHub account.
Cloning downloads the repository to your local system.
# Replace YOUR-USERNAME and REPO-NAME with your details
git clone https://github.com/YOUR-USERNAME/REPO-NAME.gitcd REPO-NAMELinking the original repository (upstream) ensures you can fetch updates from the main project.
# Replace ORIGINAL-USERNAME and REPO-NAME with the repository details
git remote add upstream https://github.com/ORIGINAL-USERNAME/REPO-NAME.gitgit remote -vYou should see:
- origin: Your forked repository
- upstream: The original repository
Always create a new branch for each feature or bug fix.
git checkout -b feature-branchReplace feature-branch with a descriptive name, e.g., add-login-functionality.
- Edit the necessary files in your preferred code editor.
- Stage changes:
git add .Or, to stage specific files:
git add filename.ext- Commit changes:
git commit -m "Brief description of changes"- Use clear and concise commit messages.
- Follow the Conventional Commit format for readability.
Push your branch to your forked repository.
git push origin feature-branch- Go to the original repository on GitHub.
- Click the Compare & pull request button.
- Write a clear title and description for your PR:
- Mention the issue number (if applicable).
- Explain your changes.
- Submit the pull request.
To keep your fork updated with the main project, sync it regularly.
# Fetch changes from the upstream repository
git fetch upstream
# Switch to the main branch
git checkout main
# Merge upstream changes into your local branch
git merge upstream/main
# Push the updated branch to your fork
git push origin maingit branch -d feature-branchgit push origin --delete feature-branch| Command | Description |
|---|---|
git status |
Check the current status of the repository. |
git log |
View commit history. |
git diff |
Show changes not yet staged. |
git stash |
Temporarily save changes without committing. |
git pull upstream main |
Sync your local branch with the main project. |
git rebase -i |
Interactively rebase commits. |
- Explore projects and understand their codebase.
- Look for "Good First Issue" or "Help Wanted" tags.
- Read the
README.mdandCONTRIBUTING.mdfiles. - Set up the project locally and run tests.
- Join the project’s Slack, Discord, or mailing lists.
- Discuss your ideas before starting work.
- Follow coding standards.
- Add comments and documentation.
- Ensure your changes don’t break existing functionality.
- Write unit tests if required.
- Not Syncing Regularly: Always pull updates from the upstream repository.
- Large PRs: Break your changes into small, manageable PRs.
- Ignoring Guidelines: Follow the project’s contribution guidelines.
- Poor Commit Messages: Use descriptive and meaningful commit messages.
- View Git history, line changes, and blame directly in VS Code.
- Features:
- File and line blame annotations.
- Commit browsing and searching.
- Visualize the Git history and branches in graph format.
- Features:
- Interactive branch management.
- Detailed commit visualization.
- Manage PRs and issues directly within VS Code.
- Features:
- Create and review PRs.
- Browse and edit issues.
- Highlights errors and warnings in your code as you type.
- Easily write and preview markdown files.
- Features:
- Live preview.
- Table of contents generation.
- Auto-format code to maintain consistency.
- Features:
- Supports multiple languages.
- Customizable formatting rules.
By following this guide, you can effectively contribute to GitHub projects and prepare for GSoC or any open-source initiative. Happy coding!
In a team project, as the maintainer of the repository, you will manage the contributions of other developers. Contributors will fork your repository, create branches, and submit pull requests (PRs) to merge their changes. The process of merging PRs requires careful review, testing, and ensuring that the code adheres to project standards. This guide provides detailed instructions on how to handle contributions, review PRs, and merge changes effectively.
- Fork the repository: If contributors don’t have direct write access, they fork the repository.
- Create a new branch: Contributors create a new branch for their changes.
- Make changes: Changes are made in the new branch.
- Commit and push: Changes are committed and pushed to the contributor’s fork.
- Create a pull request (PR): Contributors submit a PR to the original repository for merging.
- Review pull requests (PRs): Review the submitted PRs from contributors.
- Test the changes: Ensure the changes are functional and do not break existing code.
- Handle merge conflicts: Resolve any conflicts between branches before merging.
- Merge the PR: Once reviewed and approved, the PR is merged into the main branch.
If you don't have write access to the repository, you need to fork it first. This allows you to make changes without directly affecting the original codebase.
- Go to the repository page on GitHub.
- Click on the "Fork" button at the top-right corner.
- Once the repository is forked, clone it to your local machine:
git clone https://github.com/your-username/repository-name.git
cd repository-nameIt’s important to create a separate branch to work on your changes, rather than working directly on the main branch.
Create and switch to a new branch:
git checkout -b feature/branch-nameOnce on your new branch, make the necessary changes to the codebase.
Make the required changes (bug fixes, features, or updates). Stage the changes:
git add .Commit the changes with a clear message:
git commit -m "Describe the changes made"After committing your changes, push the changes to your forked repository.
Push your branch to your forked repository:
git push origin feature/branch-nameAfter pushing your changes, submit a pull request (PR) to propose merging your branch into the original repository.
- Go to the Pull Requests tab in the original repository.
- Click "New Pull Request".
- Select the branch you want to merge and compare it with the main branch.
- Provide a descriptive title and explanation for your changes.
- Click "Create Pull Request".
Before merging a PR, review the changes thoroughly to ensure they meet the following criteria:
- Code Quality: Ensure that the code is clean, well-structured, and follows the project's coding guidelines.
- Documentation: Verify that the code is well-commented and documented if necessary.
- Testing: Ensure that the changes are adequately covered by unit or integration tests.
- Functionality: Ensure the code changes work as expected and address the original issue or feature request.
- Go to the Pull Requests tab in the repository.
- Click on the PR to view the changes.
- Review the files changed, check for any issues, and verify the functionality.
Before merging, make sure the changes pass all tests. This can be done by:
- Running the tests locally on your machine.
- Verifying that the PR passes the CI (Continuous Integration) tests.
# Example for Python projects with pytest
pytestIf the tests fail, communicate with the contributor about the issues and request changes.
Sometimes, changes in the pull request might conflict with the changes in the main branch. In such cases, you need to resolve merge conflicts manually.
- Fetch the latest changes from the main branch:
git fetch origin
git checkout main
git pull origin main- Switch to the contributor's branch:
git checkout feature/branch-name- Merge the main branch into the feature branch to resolve conflicts:
git merge main- If there are any conflicts, manually resolve them by editing the conflicted files.
- Stage the resolved files:
git add .- Commit the merge:
git commit -m "Resolved merge conflicts"Once the PR is approved and all tests pass, it’s time to merge it into the main branch.
- Go to the Pull Requests tab.
- Ensure the PR is ready to be merged (no conflicts, all tests passing).
- Click on "Merge Pull Request".
- Confirm the merge.
You can choose to merge via:
- Merge Commit: Keeps the full history of the branch.
- Squash and Merge: Combines all commits into one.
- Rebase and Merge: Reapplies commits from the PR on top of the base branch.
After merging a pull request, there are a few post-merge actions to consider:
- Delete the Feature Branch: You can delete the contributor's branch after merging it.
- Update the Repository: If there are any new dependencies or configurations, update the repository’s documentation or settings.
- Communicate with the Contributor: Inform the contributor that their PR has been merged and thank them for their contribution.
Merging is a crucial part of team collaboration in software development. As the maintainer, you must ensure that the code is well-reviewed, tested, and correctly merged to keep the project’s codebase stable. By following the steps outlined in this guide, you can effectively manage contributions and maintain a high-quality codebase.
- Always create a new branch for each change.
- Write clear commit messages.
- Make sure to run tests before submitting a PR.
- Stay up-to-date with the main branch to avoid conflicts.