Git Commands With Examples
Git Commands With Examples
In the previous blog, you got an understanding of what git is. In this blog, I will talk about the
Top 20 Git Commands that you will be using frequently while you are working with Git.
git con ig
git init
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git push
git pull
git stash
Git Commands
git config
Usage: git config –global user.name “[lakshmikanth]”
This command sets the author name and email address respectively to be used with your
commits.
git init
Usage: git init [repository name]
git clone
Usage: git clone [url]
git commit
Usage: git commit -m “[ Type in the commit message]”
This command records or snapshots the ile permanently in the version history.
This command commits any iles you’ve added with the git add command and also commits
any iles you’ve changed since then.
git diff
Usage: git diff
This command shows the ile differences which are not yet staged.
This command shows the differences between the iles in the staging area and the latest
version present.
This command shows the differences between the two branches mentioned.
git reset
Usage: git reset [file]
This command undoes all the commits after the speci ied commit and preserves the changes
locally.
Usage: git reset –hard [commit] This command discards all history and goes back to
the speci ied commit.
git status
Usage: git status
git rm
Usage: git rm [file]
This command deletes the ile from your working directory and stages the deletion.
Git Rm Command - Git Commands - Edureka
This command is used to list the version history for the current branch.
This command lists version history for a ile, including the renaming of iles also.
git show
Usage: git show [commit]
This command shows the metadata and content changes of the speci ied commit.
git tag
Usage: git tag [commitID]
git branch
Usage: git branch
This command lists all the local branches in the current repository.
git checkout
Usage: git checkout [branch name]
git merge
Usage: git merge [branch name]
This command merges the speci ied branch’s history into the current branch.
git remote
Usage: git remote add [variable name] [Remote Server Link]
This command is used to connect your local repository to the remote server.
git push
Usage: git push [variable name] master
Thi d d th itt d h f t b ht t it
This command sends the committed changes of master branch to your remote repository.
git pull
Usage: git pull [Repository Link]
This command fetches and merges changes on the remote server to your working directory.
git stash
Usage: git stash save
This command temporarily stores all the modi ied tracked iles.
Want to learn more about git commands? Here is a Git Tutorial to get you started.
Alternatively, you can take a top-down approach and start with this DevOps Tutorial.