A beginner-friendly guide to essential Git commands with clear explanations and examples.
The git clone command is used to download the source code from a remote repository (like GitHub, Bitbucket, or GitLab).
git clone <https://url-of-the-repository>When you clone a repo, the code is automatically downloaded to your local machine.
This command shows which files are modified, untracked, or staged.
git statusEvery time you create, delete, or modify a file, you must stage it using git add.
git add <file-name>To add all modified files:
git add -ANote:
git addonly stages changes. It does not save them permanently or push them anywhere.
Think of the Git Commit command like a checkpoint in your development process.
Commit all staged changes:
git commitCommit all tracked files directly:
git commit -aCommit with a message:
git commit -am "<commit-message>"Note: Commits are stored only in your local repository until you push them.
Push your committed changes to the remote repository:
git push <remote> <branch-name>Only committed changes will be pushed.
Download and merge the latest changes from the remote repo into your local branch:
git pull <remote> <branch-name>Branches allow you to work on different features independently.
git branch <branch-name>git checkout <branch-name>git switch -c <branch-name>git branchMerge another branch into your current branch:
git merge <branch-name>View commit history:
git logView connected remote repositories:
git remote -vTemporarily save uncommitted changes:
git stashRestore them later:
git stash popUndo commits or remove changes.
Undo last commit but keep changes:
git reset --soft HEAD~1Undo last commit AND delete changes permanently:
git reset --hard HEAD~1--hard removes changes permanently.
If you find this helpful, consider supporting me:
- Sponsor Me: Buy Me a Coffee!
- This project is licensed under the MIT License.
- Meet T-Bot - Discover My Work
- Tushar Bhardwaj - Portfolio
- Connect 1:1 - Topmate
- GitHub: TuShArBhArDwA
- LinkedIn: Tushar Bhardwaj
- Email: [email protected]