Top Ten GIT Commands and How to undo git commands

Sun, Nov 22, 2020

Read in 3 minutes

We all know that GIT is used as a source control tool. Here I have listed out the important commands which are useful in daily life.

First, you have to install GIT software in your machine and to checkout code and check-in the code, you should create a repository .

To clone the repository: git clone <repo path>

Image text

In the above picture, git repo path is

Add your changes to the files.

To check-in the files and to add into the server,

To commit the changes: git commit -m <commit message >

To push the files into server: git push origin <branchname>

To ignore the SSL validation : git config http.sslVerify false

IF you feel lazy to do all the above commands ,you can install GIT desktop and you can push the code without using any command. So ,to get git desktop in your computer ,go to your repository and click on “clone or download” and select “open in desktop” option.

Image text

Then the git desktop installable will be downloaded and if you double click on the file ,git desktop will be installed.

Once the GIT desktop is installed ,you can provide your authentication details and you can see the repository files from the git-desktop.

Make changes to the files in your repository and check the GIT desktop you can see the changed files under the “changes” Category.

Image text

To commit the file ,enter summary and description about the changes and click on “commit to master” (Here I am trying to push the code to master branch) .

How to Undo git commands

How to undo GIT add :

Image text

I added this file using " git add " and now I want to revert this.

To Undo the “GIT ADD " command ,

Use git restore –staged

Image text

To Undo “GIT COMMIT " command :

Do “git log” and it will show all the commit history ,then use - GIT REVERT “commit_ID”

Image text


Git pull = Git fetch + Git merge

How to squash GIT Commits :

Git rebase -i master

Git pull – rebase :

If you do rebase ,the local changes are reapplied on top of the remote changes. If you don’t want your local changes ,then git pull –no rebase will over write the local changes.

How to resolve merge conflict :

When you got the merge conflict , open the file in the IDE (any IDE like eclipse ,Intellij)and see the conflicts .Now change the content properly and commit the changes and push to remote branch.

To see Difference between two branch:

Git diff master - - dev_branch