Most used Git commands

The most used commands in Git console which are used by me in projects. The reference is often overwhelmed with information which hinders me to use it in practice. This text is the place to keep working examples for quick reference instead of looking them up from somewhere in the internet.

All examples presume a local and a remote repositories which might be maintained simultaneously in most of cases. Also you should take a note that all commands are prefixed with ‘git’ so the whole command should look like the following ‘git <command> <options> <parameters>’.

Task Commands
Reset current branch to specific commit (details)
Discard changes in current branch
Create a new branch
The first command creates a local branch. The second command creates a remote one.
Delete a branch
The first command deletes a remote branch, The second command deletes a local one.
List local and remote branches & update the list of remote branches
It shows branches in local and remote repositories.
Switch to another local branch
Merge another branch to the current one
Compare local with remote
Delete local and remote branches
Get all merge commits from branches
Revert one file to a specific commit
Untrack a file git rm –cached


Dealing with Issues

Shallow clone

After you make a shallow clone with the following command you may not be able to checkout to other remote branch.

You have to solve this with the following commands: 

Taken from here.

Some issues with NuGet in Visual Studio

It may say that NuGet configuration is invalid or some path is invalid. In such a case delete this file %AppData%/Nuget/Nuget.config. Taken from here.

See Also

No Comments

You can leave the first : )

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.