10 Git Commands Every Developer Should Know
Master Git with These Essential Commands Today
1. Git Clone
git clone
downloads an existing repository to your local machine. It's useful for getting started with a project hosted on platforms like GitHub.
git clone <https://repository-link>
2. Git Branch
Branches allow multiple developers to work on a project simultaneously. Use git branch
to create, list, or delete branches.
git branch <branch-name>
Push the new branch to the remote repository:
git push -u <remote> <branch-name>
View branches:
git branch
orgit branch --list
Delete a branch:
git branch -d <branch-name>
3. Git Checkout
git checkout
switches branches or restores working tree files. Create and switch to a new branch with:
git checkout -b <branch-name>
4. Git Status
git status
displays the state of the working directory and staging area. It lets you see which changes have been staged, which haven't, and which files aren’t being tracked by Git.
git status
5. Git Add
git add
stages changes for the next commit. Add a single file:
git add <file>
Add all changes:
git add -A
6. Git Commit
git commit
saves your changes to the local repository. Always include a message:
git commit -m "commit message"
7. Git Push
git push
uploads your local commits to a remote repository. Push your changes with:
git push <remote> <branch-name>
For a new branch:
git push --set-upstream <remote> <branch-name>
8. Git Pull
git pull
fetches and merges changes from the remote server to your working directory.
git pull <remote>
9. Git Revert
git revert
undoes changes by creating a new commit. Find the commit hash with git log --oneline
, then revert it:
git revert <commit-hash>
10. Git Merge
git merge
integrates changes from one branch into another. Switch to the branch you want to merge into:
git checkout <branch-to-merge-into>
Then merge the changes:
git merge <branch-to-merge>