Git is a magic bullet for developers to track your work. Git also differentiates the other teammate work by using git commands. Here are the 10 most used git commands.
- git init
- git clone
- git add
- git status
- git diff
- git commit
- git push
- git pull
- git revert
- git checkout
Git init is used to initialise the git to a local repository. But when are you clone from remotely then you don't need the git init.
git clone [remote_url]
Git clone is used to creating an identical copy of a Git Remote Repository to the local machine.
git add [file name/.]
Git add is used to add the modified files in the staged area. There are following ways to use git add, by adding the entire folder and specific files. Dot means the entire folder.
git commit -m "Your message about the commit"
Git commit is used to add the changes with a unique message in an individual file or set of files. Git commits also creates a unique id. A "unique message" shortly describes what changes you have done. It also helps you track your commits.
Git status is used to check the status of the modified files. It also shows which files are staged, unstaged, and untracked.
Git diff is used to track the difference between the changes made on a file.
git revert [commit id]
Git revert is used to undo the changes of the given commit which we have pushed in a "remote" repository and changes add in the current branch. Without losing your previous commit.
Git push is used to push all the changes locally to the remote repository.
Git pull is used to pull all the changes from remote to the local repository.
git checkout [file/branchname/commit id]
Git Checkout is used to switch between files, branches and commits.
In this article, I cover mostly used git commands for beginners. I also define the syntax, purpose and usage of command at one place.
I hope this article help to learn git commands.