- April
Posted By : Alexander Goida
Most used Git commands

The most used commands in 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 in

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.

Git rebase –onto

Transferring commits from one to another branches without changing already pushed commits. Schema is as follows:

After those operations you will be able to make a pull request to b3.6 branch with changes only from b3.5-c branch. But you’re not protected from conflicts you may have during the rebasing.

Conflict resolution

It’s possible to split the rebasing and conflict resolution into two different steps. The following command solves all conflicts using the version from the target branch.

After you restore the branch b3.5-c you can merge it to the target. During this merge you will need to solve conflicts.

See Also

Leave a Reply

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