πŸ“ Ultimate Git and GitHub Cheat Sheet with Examples - 50 Essential Commands πŸš€πŸ’»πŸ”§

Β·

4 min read

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

  1. git init: Initialize a new Git repository.

    • Example: git init
  2. git clone: Clone a remote repository to your local machine.

  3. git status: Check the status of your working directory.

    • Example: git status
  4. git add: Stage changes for the next commit.

    • Example: git add file.txt
  5. git commit: Commit staged changes with a descriptive message.

    • Example: git commit -m "Added new feature"
  6. git push: Push local commits to a remote repository.

    • Example: git push origin main
  7. git pull: Pull remote changes to your local repository.

    • Example: git pull origin main
  8. git branch: List all branches in the repository.

    • Example: git branch
  9. git checkout: Switch to a different branch.

    • Example: git checkout new-feature
  10. git merge: Merge changes from one branch into the current branch.

    • Example: git merge feature-branch
  11. git log: View commit history.

    • Example: git log
  12. git reset: Unstage changes and reset the repository to a specific commit.

    • Example: git reset --hard commit-hash
  13. git stash: Temporarily save changes without committing.

    • Example: git stash save "Work in progress"
  14. git cherry-pick: Selectively apply specific commits to another branch.

    • Example: git cherry-pick commit-hash
  15. git fetch: Fetch changes from a remote repository without merging.

    • Example: git fetch origin
  16. git revert: Create a new commit that undoes a previous commit.

    • Example: git revert commit-hash
  17. git tag: Create and manage tags for specific commits.

    • Example: git tag v1.0.0
  18. git diff: Show changes between commits, branches, or files.

    • Example: git diff branchA branchB
  19. git remote add: Add a new remote repository to your Git project.

  20. git rm: Remove files from the repository and working directory.

    • Example: git rm file.txt

πŸ’»GitHub Commands

  1. git blame: Show who last modified each line in a file.

    • Example: git blame file.txt
  2. git config: Configure Git settings.

    • Example: git config --global user.name "Your Name"
  3. git show: Show information about a commit.

    • Example: git show commit-hash
  4. git fetch: Download objects and refs from another repository.

    • Example: git fetch origin
  5. git log: Show commit logs.

    • Example: git log
  6. git grep: Print lines matching a pattern.

    • Example: git grep "keyword"
  7. git revert: Revert a commit.

    • Example: git revert commit-hash
  8. git blame: Show what revision and author last modified each line of a file.

    • Example: git blame file.txt
  9. git remote show: Show information about a remote.

    • Example: git remote show origin
  10. git rebase: Reapply commits on top of another base tip.

    • Example: git rebase branch-name
  11. git log --graph: Show a graph of the commit history.

    • Example: git log --graph
  12. git bisect: Use binary search to find the commit that introduced a bug.

    • Example: git bisect start
  13. git reflog: Show a log of reference changes.

    • Example: git reflog
  14. git branch -d: Delete a branch.

    • Example: git branch -d branch-name
  15. git remote rename: Rename a remote.

    • Example: git remote rename old-name new-name
  16. git remote set-url: Change the URL of a remote repository.

    • Example: git remote set-url origin new-url
  17. git remote remove: Remove a remote repository.

    • Example: git remote remove origin
  18. git log --author: Show commits by a specific author.

    • Example: git log --author "John Doe"
  19. git log --oneline: Show a concise log with each commit on a single line.

    • Example: git log --oneline
  20. git revert --no-commit: Revert changes but do not create a commit.

    • Example: git revert --no-commit commit-hash
  21. git commit --amend: Modify the last commit.

    • Example: git commit --amend
  22. git merge --abort: Abort a merge in progress.

    • Example: git merge --abort
  23. git cherry-pick --abort: Abort a cherry-pick in progress.

    • Example: git cherry-pick --abort
  24. git clean: Remove untracked files from the working directory.

    • Example: git clean -f
  25. git log --grep: Show commits with a specific commit message.

    • Example: git log --grep "bug fix"
  26. git rebase --continue: Continue a rebase after resolving conflicts.

    • Example: git rebase --continue
  27. git blame --date: Show the date each line was last modified.

    • Example: git blame --date file.txt
  28. git stash list: List all stashed changes.

    • Example: git stash list
  29. git stash pop: Apply the most recently stashed changes and remove them from the stash.

    • Example: git stash pop
  30. git stash apply: Apply the most recently stashed changes without removing them from the stash.

    • Example: git stash apply

🌟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! 🌟πŸ”₯

Β