30 Git Commands

30 Git Commands Every Developer Should Know

Certainly! Here’s an expanded list of 30 Git commands that every developer should know:

  1. git init: Initialize a new Git repository in the current directory.
  2. git clone [repository_url]: Clone a remote repository to your local machine.
  3. git add [file]: Stage a file for commit. Use “.” to stage all changes.
  4. git commit -m “[commit_message]”: Commit your staged changes with a descriptive message.
  5. git status: Check the status of your working directory and see which files are modified, staged, or untracked.
  6. git diff: Display the differences between your working directory and the last commit.
  7. git log: View the commit history, showing the author, date, and commit message.
  8. git branch: List all branches in your repository. The active branch is highlighted.
  9. git checkout [branch_name]: Switch to a different branch in your repository.
  10. git merge [branch_name]: Merge the changes from one branch into another.
  11. git pull: Fetch changes from a remote repository and merge them into your current branch.
  12. git push [remote_name] [branch_name]: Push your local changes to a remote repository.
  13. git remote -v: List all remote repositories associated with your local repository.
  14. git remote add [remote_name] [repository_url]: Add a new remote repository to your local repository.
  15. git stash: Temporarily save your changes without committing them, allowing you to switch branches or pull changes.
  16. git reset [file]: Unstage a file that you’ve added for commit.
  17. git revert [commit]: Create a new commit that undoes the changes introduced by a specific commit.
  18. git fetch: Download new changes from a remote repository without merging them.
  19. git tag [tag_name]: Create a new tag to mark a specific commit, often used for versioning.
  20. git rm [file]: Remove a file from the working directory and stage the deletion for commit.
  21. git show [commit]: Display information about a specific commit, including the changes introduced.
  22. git config –global user.name “[your_name]”: Configure your global Git username.
  23. git config –global user.email “[your_email]”: Configure your global Git email.
  24. git cherry-pick [commit]: Apply the changes introduced by a specific commit to your current branch.
  25. git remote remove [remote_name]: Remove a remote repository from your local repository.
  26. git rebase [branch]: Reapply commits from one branch on top of another, often used to maintain a linear commit history.
  27. git log –graph –oneline –all: Visualize the commit history in a compact graph format.
  28. git bisect: Use binary search to find the commit that introduced a bug.
  29. git blame [file]: Display the author and last modification for each line in a file.
  30. git config –global alias.[alias_name] “[command]”: Create custom Git aliases to shorten commonly used commands.

With these Git commands, you’ll have a solid foundation to effectively manage your codebase, collaborate with others, and maintain a clean version history.