Complete List of Git Commands and Their Usage (2025 Guide)
Git is one of the most powerful and widely-used version control systems in the software development world. Whether you're a beginner or an experienced developer, knowing the right Git commands can significantly enhance your workflow and productivity. we’ll walk through a comprehensive list of Git commands along with their usage, syntax, and real-world examples. This extended guide aims to provide you with an in-depth understanding of Git’s capabilities and how to make the most out of them in day-to-day development.
Basic Git Commands
1. git init
Usage: Initializes a new Git repository.
git initExample: Start version control in a new project directory to begin tracking file changes locally.
2. git clone <repo-url>
Usage: Clones a remote repository into your local machine.
git clone https://github.com/username/repo.gitExample: Make a full copy of a remote repository, including all files, commits, and branches.
3. git status
Usage: Shows the current status of files in the working directory.
git status
Example: Check which files are staged, unstaged, or untracked before committing.
4. git add <file>
Usage: Adds a file to the staging area.
git add index.htmlExample: Stage specific changes to be included in the next commit.
5. git commit -m "message"
Usage: Commits the staged changes with a message.
git commit -m "Initial commit"Example: Save the snapshot of the staged changes with a meaningful message.
6. git config
Usage: Configure Git settings like username and email.
git config --global user.name "Your Name"Example: Set global user configuration to identify who makes commits.
Branching and Merging
7. git branch
Usage: Lists all local branches.
git branchExample: View available branches in your repository.
8. git branch <branch-name>
Usage: Creates a new branch.
git branch feature/loginExample: Start working on a new feature without affecting the main codebase.
9. git checkout <branch-name>
Usage: Switches to the specified branch.
git checkout mainExample: Move between branches to test or work on different code.
10. git checkout -b <branch-name>
Usage: Creates and switches to a new branch.
git checkout -b feature/signupExample: Quickly create and begin working on a new feature.
11. git merge <branch-name>
Usage: Merges the specified branch into the current branch.
git merge feature/signupExample: Combine changes from a feature branch into your main branch.
Working with Remote Repositories
12. git remote -v
Usage: Shows remote URLs.
git remote -vExample: Check the URLs connected to your remote origin.
13. git remote add origin <repo-url>
Usage: Sets a new remote repository.
git remote add origin https://github.com/user/repo.gitExample: Link your local repository to a remote GitHub repo.
14. git push -u origin <branch-name>
Usage: Pushes a branch to remote and tracks it.
git push -u origin mainExample: Upload your local branch to GitHub and set it to track future changes.
15. git pull
Usage: Pulls the latest changes from the remote.
git pullExample: Update your local codebase with the latest changes from the origin.
16. git fetch
Usage: Downloads new data from the remote without merging.
git fetchExample: Retrieve latest commits, branches, and tags without applying changes.
Cleaning and Resetting
17. git reset <file>
Usage: Unstages a file.
git reset index.htmlExample: Remove a file from the staging area while keeping the changes in the working directory.
18. git reset --hard
Usage: Resets working directory and staging area to last commit.
git reset --hardExample: Discard all uncommitted changes and reset to the last commit state.
19. git clean -fd
Usage: Removes untracked files and directories.
git clean -fdExample: Clean up your workspace by deleting files not under version control.
Git Log and History
20. git log
Usage: Shows the commit history.
git logExample: View detailed logs including commit hashes, authors, and messages.
21. git log --oneline
Usage: Shows a compressed view of commit logs.
git log --onelineExample: Display a simplified list of commits in one line each.
22. git diff
Usage: Shows the difference between commits, branches, and files.
git diffExample: Compare changes between working directory and staging area or between commits.
Advanced Git Commands
23. git stash
Usage: Temporarily saves uncommitted changes.
git stashExample: Store your changes safely before switching branches.
24. git stash apply
Usage: Reapplies the last stash.
git stash applyExample: Restore stashed changes after you've completed other work.
25. git rebase <branch>
Usage: Moves or combines commits.
git rebase mainExample: Reapply commits from one branch onto another for cleaner history.
26. git cherry-pick <commit>
Usage: Applies a commit from one branch onto another.
git cherry-pick abc1234Example: Selectively apply a specific commit without merging the whole branch.
27. git tag
Usage: Tags specific commits.
git tag v1.0.0Example: Mark significant points in your project's history, like releases.
Conclusion
Understanding and mastering Git commands is essential for efficient version control and collaborative software development. Whether you're managing personal projects or working in a team, Git gives you full control over your code changes. Bookmark this guide and refer to it whenever you need to remember a Git command, explore new features, or teach others how to use Git.
Stay tuned for more in-depth tutorials, developer-friendly guides, and cutting-edge tech resources throughout 2025 and beyond!
💬 Have questions or suggestions? Feel free to comment below or reach out — let’s grow together as developers!
