Mostly Used GIT Commands

Git is the distributed version-control open source system, it was originally developed in 2005 by Linus Torvalds.
GIT is used for track/manage the changes during software development. GIT is popular due to its great features like Performance, Security, Flexibility, Version control etc.

Mostly Used GIT Commands

git config: The command is used to set the author name and email who access the git.
git config –global “name”: This command will set the user globally in current system with keyword “-global”, if we
omit “-global” it will set name for current repository only.

git config –global “email_address”: This command will set email address for all repository under current system.

git init: This command will initialize the repository at current path and create .git directory at current path,
and if we need to create new repository than we can run this command along with name of new repository as “git init [new repository name]”

git clone [repository_url]: This command is used to clone/copy the existing repository to local system.

git add [single file or wild card keyword like .,directory_apth/*]: This command is used to add the file/files to staging area, as before
pushing any code at repository/branch we must have to add it in staging area.

git commit -m “[commit name]” : This command is used to permanently add files in version history under the mentioned commit name, so all the files added after the last commit and before the current commit will be identified with current commit.

git push [‘origin-name’] master: This command will publish(push) your committed local changes under specified origin on master branch.

git diff: This command will show the difference of changes along with files after last commit.

git diff –staged: This command will show difference of changes only from the files that is staged after last commit.

git diff [branch-1 branch-2] :This command will show the changes between two branches.

git diff [branch-1 branch-2] :This command will show the changes between two branches.

git reset [file-name-with-path]: This command will undo the changes from last staged (undo of last git add [file]) but do not change original file.

git reset [desired-commit]: This command undoes the commits after specified commit but do not change local file contents.

git reset –hard [desired-commit]: This command will destroy all the commit history after specified commit and make files as its were at specified commit.

git status: This command will list files that is changed after last commit and also shows some other info like branch name, staged/unstaged files but do not show the contents of changed files.

git rm [files/directory(wildcard like .,*)]: This command remove the specified files from current working directory as well as from git cache if file’s is/are already staged than you need use flag -f from remove forcefully or –cached to keep file but make it unstaged.

git log: This command will list the version history, along with author info and committed date of current branch.

git show: This command will show the metadata(author info, committed date etc) along with the contents of files that was committed.

git tag [commit-id]: This command will list the tags with specified commit-id.

git branch [new branch name]: This command will create new branch with the specified branch name.

git branch -d [branch name to be deleted]: This command will delete the specified branch.

git checkout [branch name]: This command will create new branch with specified branch name and set new branch as current active branch.

git merge [branch name]: This command merge specified branch’s history to current active branch.

git remote add [remote-name] [remote-branch-address]: This command set the specified remote origin to local branch.
Example: git remote add origin

git remote -v: This command list the associated origin’s under the current branch.

git pull [repository-name]: This command get the changes from live repository to local repository and if there any conflicts occurs it will also list the conflicted files along with possible solutions.

git stash save: This command temporary staged current changes files so you can switch/create new branch or push changes from master branch.

git stash pop: This command restore the last stashed changes and make it active changes so you can push it on live or make anymore changes.

git stash list: This command lists the stashed changes in list.

git stash drop: This command delete the last stashed changes.

Leave a Reply