Git Cheat sheet

Photo by Yancy Min on Unsplash

Git commands which software development teams uses/come across frequently.

  1. Create new remote repository and add it to local repo:
  • First create a repository on GitHub and copy it’s URL.
  • Initialize a local folder/directory as Git repo .
$ git init
  • Add new remote repo to local directory.
$ git remote add origin

2. Get status of all changes made on local repository:

$ git status .

3. Add all the changes to remote repository:

$ git add .

4. Committing and pushing to remote repository:

$ git commit -m "A short message for list of changes made"
$ git push
$ git push -f #to forcefully push regardless of warning

5. New branch creation: git branch <branch-name> creates the branch and git checkout <branch-name> changes the current branch to newly created branch.

$ git branch first-react-project
$ git checkout first-react-project
#Shortcut way...just need one command
$ git checkout -b first-react-project

6. Pushing new local branch to remote

git push --set-upstream origin <local-branch-name>

7. Copying the content from one branch to another:

  • Copying content of another branch into current branch locally.
  • Committing the changes
  • Pushing the modifications
$ git checkout master . #copies content present in master to present                        branch
$ git commit -m "Copied project from master branch"
$ git push -u origin first-react-project

8. Delete a branch: Ensure you are currently out of the branch which is to be deleted.

$ git branch -d first-project #deletes locally
$ git push origin --delete first-project #deletes remote branch

9. List branches for the repo:

$ git branch
* learner-react-projects

10. Overwrite content of master with content of another branch: Suppose I want to overwrite all content of master with that of ‘learner-react-projects’ branch.

$ git checkout learner-react-projects
$ git merge -s ours master
$ git checkout master
$ git merge learner-react-projects




Learner. Observer. Interested in software development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Guard your open-sourced Flutter app with GitHub Actions

topLayoutGuide & bottomLayoutGuide in iOS

Towards the Road to Serverless !

Go: Buffalo Web development eco-system

Github dot Dev

Azure AI Speech to Text Demo

Wikimedia Hackathon Vienna — 2017

Looking for an API to get Indian Gold and Silver (Per Karat) live rates? Check this company

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akanksha Pardeshi

Akanksha Pardeshi

Learner. Observer. Interested in software development.

More from Medium


Github & Its Basic Commands

GIT commands

Git and GitHub.