π Ultimate Git and GitHub Cheat Sheet with Examples - 50 Essential Commands ππ»π§
Table of contents
Hi there, use this comprehensive cheat sheet to harness the full potential of Git and GitHub for version control and collaborative coding projects! ππ»π
π»Git Commands
git init: Initialize a new Git repository.
- Example:
git init
- Example:
git clone: Clone a remote repository to your local machine.
- Example:
git clone
https://github.com/username/repository.git
- Example:
git status: Check the status of your working directory.
- Example:
git status
- Example:
git add: Stage changes for the next commit.
- Example:
git add file.txt
- Example:
git commit: Commit staged changes with a descriptive message.
- Example:
git commit -m "Added new feature"
- Example:
git push: Push local commits to a remote repository.
- Example:
git push origin main
- Example:
git pull: Pull remote changes to your local repository.
- Example:
git pull origin main
- Example:
git branch: List all branches in the repository.
- Example:
git branch
- Example:
git checkout: Switch to a different branch.
- Example:
git checkout new-feature
- Example:
git merge: Merge changes from one branch into the current branch.
- Example:
git merge feature-branch
- Example:
git log: View commit history.
- Example:
git log
- Example:
git reset: Unstage changes and reset the repository to a specific commit.
- Example:
git reset --hard commit-hash
- Example:
git stash: Temporarily save changes without committing.
- Example:
git stash save "Work in progress"
- Example:
git cherry-pick: Selectively apply specific commits to another branch.
- Example:
git cherry-pick commit-hash
- Example:
git fetch: Fetch changes from a remote repository without merging.
- Example:
git fetch origin
- Example:
git revert: Create a new commit that undoes a previous commit.
- Example:
git revert commit-hash
- Example:
git tag: Create and manage tags for specific commits.
- Example:
git tag v1.0.0
- Example:
git diff: Show changes between commits, branches, or files.
- Example:
git diff branchA branchB
- Example:
git remote add: Add a new remote repository to your Git project.
- Example:
git remote add origin
https://github.com/username/new-repo.git
- Example:
git rm: Remove files from the repository and working directory.
- Example:
git rm file.txt
- Example:
π»GitHub Commands
git blame: Show who last modified each line in a file.
- Example:
git blame file.txt
- Example:
git config: Configure Git settings.
- Example:
git config --global
user.name
"Your Name"
- Example:
git show: Show information about a commit.
- Example:
git show commit-hash
- Example:
git fetch: Download objects and refs from another repository.
- Example:
git fetch origin
- Example:
git log: Show commit logs.
- Example:
git log
- Example:
git grep: Print lines matching a pattern.
- Example:
git grep "keyword"
- Example:
git revert: Revert a commit.
- Example:
git revert commit-hash
- Example:
git blame: Show what revision and author last modified each line of a file.
- Example:
git blame file.txt
- Example:
git remote show: Show information about a remote.
- Example:
git remote show origin
- Example:
git rebase: Reapply commits on top of another base tip.
- Example:
git rebase branch-name
- Example:
git log --graph: Show a graph of the commit history.
- Example:
git log --graph
- Example:
git bisect: Use binary search to find the commit that introduced a bug.
- Example:
git bisect start
- Example:
git reflog: Show a log of reference changes.
- Example:
git reflog
- Example:
git branch -d: Delete a branch.
- Example:
git branch -d branch-name
- Example:
git remote rename: Rename a remote.
- Example:
git remote rename old-name new-name
- Example:
git remote set-url: Change the URL of a remote repository.
- Example:
git remote set-url origin new-url
- Example:
git remote remove: Remove a remote repository.
- Example:
git remote remove origin
- Example:
git log --author: Show commits by a specific author.
- Example:
git log --author "John Doe"
- Example:
git log --oneline: Show a concise log with each commit on a single line.
- Example:
git log --oneline
- Example:
git revert --no-commit: Revert changes but do not create a commit.
- Example:
git revert --no-commit commit-hash
- Example:
git commit --amend: Modify the last commit.
- Example:
git commit --amend
- Example:
git merge --abort: Abort a merge in progress.
- Example:
git merge --abort
- Example:
git cherry-pick --abort: Abort a cherry-pick in progress.
- Example:
git cherry-pick --abort
- Example:
git clean: Remove untracked files from the working directory.
- Example:
git clean -f
- Example:
git log --grep: Show commits with a specific commit message.
- Example:
git log --grep "bug fix"
- Example:
git rebase --continue: Continue a rebase after resolving conflicts.
- Example:
git rebase --continue
- Example:
git blame --date: Show the date each line was last modified.
- Example:
git blame --date file.txt
- Example:
git stash list: List all stashed changes.
- Example:
git stash list
- Example:
git stash pop: Apply the most recently stashed changes and remove them from the stash.
- Example:
git stash pop
- Example:
git stash apply: Apply the most recently stashed changes without removing them from the stash.
- Example:
git stash apply
- Example:
πConclusion
In conclusion, this comprehensive "Git and GitHub Cheat Sheet with Examples" provides developers with a powerful toolkit to master version control and collaboration. ππ»π§ From initializing a new repository to cherry-picking specific commits, these commands streamline project management and code sharing. The cheat sheet also covers essential functionalities like branching, merging, and managing remote repositories. πͺπ Embrace these commands to enhance your coding skills and work seamlessly with Git and GitHub, making software development a breeze! Happy coding! ππ₯