Cheatsheet of git commands

Get current branch

Above command will list out all the branches in your current working directory that you checked out. The current active branch will have a asterik mark before it.

Switch to different branch

Say you are working on master branch. Now you need to switch to branch named develop

Create new branch

Below command will create a new branch locally

To push this to remote origin

Delete a branch

Below command will delete branch from local repository

Show latest commit history

Set email and name globally

Set meld as difftool

View difference between local repository and remote origin in meld

In above command if you use diff instead of difftool git will show the difference in command prompt

Fetch new branch from remote origin

Say a new branch has been added in the remote repository. You need to fetch the remote new branch in your local git repository

Merge single commit from another branch

Revert conflict changes for cherry pick

While cherry picking if there are conflicts and say you want to abort the conflict and cherry picking instead of solving it

Revert add

Say you did a git add some_file.txt and now you want to undo it and don’t want to commit.

Selectively merge

Say you created a branch develop from master

Then there was a commit made to master. Simultaneous commits were made to develop. Now we need to selectively pull changes in develop to master

In git rebase -i master the i flag tells git to interactively rebase. Thus it opens a editor. Use the instructions at the bottom of the terminal to edit the file.

Hard revert a commit

Leave a Reply

Your email address will not be published. Required fields are marked *