Skip to main content

#Git starter cheat sheet

Initialize a local repo

Run the following command in the folder where you would like to initialize a git repo.

git init

Get status

It is a good practice to frequently run check on status during development. The following command points out the changes between the previous commit and current state of the folder.

git status

Add content

To add an untracked file named ‘text.txt’ to the staging area, execute the following command.

git add text.txt

Syntax: git add <filename>

Commit changes

To commit changes made to the folder, execute the following command. The message will be used as a commit message to associate this check-in with the message.

git commit –m “Add text.txt to the code base.”

Syntax: git commit –m “<Commit message>”

Add using wild card

To add multiple files using a wild card character, execute the following command.

git add ‘*.txt’

Syntax: git add ‘<wildcard_character+string>’

Check history

Review commit history using the following command.

git log

Add Remote repository

To push the local repo to the remote git server, we need to add a remote repository.

git remote add origin http://<remote_host>/<repo_name>/<repo+name>.git

Pushing remotely

The push command tells Git where to put our commits. The name of our remote is origin and the default local branch name is master. The -u option allows git to remember the parameters for subsequent pushes.

git push -u origin master

Pulling remotely

Pull the latest changes from the remote repository to your local repository. All changes since your last push will be pulled down to the local repo.

git pull origin master

Identifying differences

The following command shows the differences between our last commit and the current state of the remote repo. HEAD refers to our recent commit.

git diff HEAD

Staged differences

The diff command can also be used to identify changes within the files that have already been staged.

git diff --staged

Resetting the staged additions

Sometimes, we may choose to un-stage changes that have not been pushed to the repo.

git reset <repo_name>/<file_name>


Files can be changed back to the way they were at the last commit. When this command is executed, any files that were not committed will be removed from the local folder.

git checkout -- <filename_to_be_removed>

Creating a branch

git branch <branch_name>

Display branches

View list of all branches using the following command.

git branch

Switching branches

To switch to a branch, execute the following.

git checkout <branch_name>


Delete one or more files from the branch or master.

git rm ‘*.txt’
git rm text.txt

Committing branch changes

git commit –m “<message_text>”

Switching back to master

To merge or copy your changes made in the branch to your master, first switch over to the master branch.

git checkout master

Perform merge

Prepare to merge changes from branch to master.

git merge <branch_name_to_copy_from>
git push

Clean up branch

git branch –d <branch_name_to_cleanup>

List all remotes

git remote -v

Revert local changes

git checkout .
git reset

Delete last remote commit 

git reset --soft HEAD~1
git stash
git push -u -f origin master


git rebase -i <commit_hash>

pick/drop hashes as needed

Resolve any merge conflicts and git add *

git rebase --continue

git push -u origin master

Remove untracked files

git clean -f

Remove untracked files and directories

git clean -fd


git tag <tag_name>
git push -u origin <branch> --tags

Git log readable one line

git log --pretty=oneline 

git log --pretty=oneline -5 (last five commits)

Popular posts from this blog

A @trello board to get kids excited

My 8 year old just started his summer break. He did so well in school and I am proud of him. He skipped second grade, got into the gold honor roll in every quarter and got a medal for doing that. Last night, I promised to install a new app for him on his iPad mini. I installed Trello and created a board for him while he watched. I showed him how to create cards, add labels to them and move them from To Do, to Doing to Done. I had him create some cards and label them. He could not stop creating cards. I could not convince him to go to bed after that. He created cards for everything he wants to do in the summer and he is not done with creating cards. He even created a card to email a screenshot of his Trello board to his teacher. Later last night, he was still awake in bed when I checked on him. He told me that he wanted to add three more labels - Math, Science and One-on-One. He wanted a label titled 'One-on-one' for tasks that he wants to do with me and he wants one-on-one at

Create #VirtualPrivateCloud, NAT Instance and NAT Gateways on @AWSCloud

Create a Virtual Private Cloud, NAT instance and the new NAT Gatweay ... and making it all work. This is a YouTube playlist of three videos.

Cheat sheet to create a #VPC and Subnets on @AWSCloud

One of the critical things to remember for working with a AWS VPC is creating and using it. I had hard time remembering how to do it, so, I wrote down a cheat sheet for myself.  If anyone wants to follow along, just navigate to the VPC page on the AWS Console and start with 'Create VPC' button. Please note that this may cost some dollars if you are not on the free tier. If you are on the free tier and make mistakes, it may cost some dollars. In the steps below, we will be creating the following on a new VPC: An internet gateway One public subnet with routes for accessibility from the internet One private subnet without any routes One EC2 web server with Apache installed in it and serving a sample html page - using the public subnet. One EC2 server with the private subnet and security group that allows access to resources running on the public subnet only.  Create VPC Name tag: myVPC CIDR Block: Tenancy: default (Must have default. Otherwise, it