Git Commands Every Developer Should Know
Git is a version control system that helps developers track code changes, manage branches, collaborate with teams, and maintain project history. Whether you're working on a personal project or a production application, Git plays an important role in managing your codebase.
Here are the most useful Git commands categorised by their purpose.
1. Repository Setup
Command | Purpose |
| Initialize a new Git repository |
| Clone an existing repository |
| Configure Git username |
| Configure Git email |
| View Git configuration |
2. Checking Changes
Command | Purpose |
| Check current repository status |
| View unstaged changes |
| View staged changes |
| View commit history |
| View compact commit history |
| View details of a commit |
3. Adding & Committing Changes
Command | Purpose |
| Stage a specific file |
| Stage changes in the current directory |
| Stage all changes, including deletions |
| Commit staged changes |
| Modify the previous commit |
| Unstage changes or move HEAD |
| Undo the previous commit but keep changes staged |
| Undo the previous commit but keep changes unstaged |
| Remove the previous commit and its changes |
4. Branch Management
Command | Purpose |
| List local branches |
| Create a branch |
| Switch branches |
| Create and switch to a new branch |
| Switch branches |
| Create and switch to a branch |
| Delete a merged branch |
| Force-delete a branch |
| Merge another branch into the current branch |
5. Remote Repository Commands
Command | Purpose |
| List remote repositories |
| View remote URLs |
| Add a remote repository |
| Remove a remote |
| Download remote changes without merging |
| Fetch and integrate remote changes |
| Push commits to the remote repository |
| Push branch and set upstream |
| Delete remote branch |
6. Undoing & Reverting Changes
Command | Purpose |
| Discard working-directory changes |
| Unstage a file |
| Create a commit that reverses a previous commit |
| Reset staging area |
| Reset working directory and index |
| Preview untracked files to be removed |
| Remove untracked files |
| Remove untracked files and directories |
7. Stashing Changes
Command | Purpose |
| Temporarily save uncommitted changes |
| Save changes with a message |
| View saved stashes |
| Apply a stash without deleting it |
| Apply and remove the latest stash |
| Delete a stash |
| Remove all stashes |
8. Removing & Renaming Files
Command | Purpose |
| Remove a file and stage the deletion |
| Remove a directory recursively |
| Rename or move a tracked file |
| Remove a file from Git tracking but keep it locally |
9. Tags
Command | Purpose |
| List tags |
| Create a tag |
| Create an annotated tag |
| View tag details |
| Push a specific tag |
| Push all tags |
| Delete a local tag |
10. Advanced & Useful Commands
Command | Purpose |
| Apply a specific commit to the current branch |
| Reapply commits on top of another branch |
| View the history of HEAD movements |
| See who changed each line and when |
| Identify the commit that introduced a bug |
| Search for text inside tracked files |
| Create an archive of repository files |
| List tracked files |
| Compare working directory against HEAD |
Conclusion
Git is more than just commit, push, and pull. It provides powerful tools for managing source code, recovering changes, collaborating with teams, and maintaining a clean development history.
Learning these commands gradually will make everyday development and Git-based workflows significantly easier.