Git Cheat Sheet For Dummies

Basic Git Commands

git status               //Shows status of working branch. Such as      
//staged/unstaged changes and new,
//Untracked file.
git ls-files //List all files in remote Dirgit logs //List details of recent commits git diff //Compare changes of local with remote

Set Up Git Project On Local System

#Create current working directory on local system as git project folder and fetch files from remote repository.git init
git remote add [remote_name] [your_project_http_address]
git fetch
git checkout [branch_name]

#Load a copy of project to current directory on local system from remote repository.git clone [your_project_http_address]

Working With Git Branches

git checkout -b [branch_name]    //Create new branchgit checkout [branch_name]       //Switch between branchgit branch -v                    //List all local branchgit branch -r                    //List all remote branchgit branch --all                 //List all branch (local+remote)git branch -d [branch_name]      //Delete local branchgit push origin :[branch_name]   //Delete remote branch

Commit & Push Changes To Git Repository

git pull                         //Fetch latest files from repogit add *                        //Stage all files with changesgit add [file1] [file2]          //Stage specific filesgit commit -m “your msg”         //Commit file to working branchgit push -u origin [branch_name] //Push commit files to repository

Revert Your Git Changes

git reset                    //Unstage all staged filesgit reset [file1] [file2]    //Unstage specific filesgit reset —-soft HEAD~1      //Undo last commit on local working
git reset —-hard HEAD~1 //Undo last commit & deletes tracked
//files from local system
git revert HEAD~1 //Undo last commit & deletes tracked
//files from local system

Merge Git Branches

git checkout [branch_name]   //Name of branch parent branch
git pull //Fetch most updated changes
git merge [branch_name] //Name of branch to be merged


#Compare files from two different branches
git diff [branch_name1] [branch_name2] ./[file_name]
#Shows graphical representation of the commit history
git log —-graph —-online —-all
#Move around and review specific commit history
git checkout [commitSHA]
#Rename remote from default "origin" to your desired choice
git remote rename [old_name] [new_name]




DevOps Engineer

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

Recommended from Medium

{UPDATE} Roar! - AR Boardgame Hack Free Resources Generator

[Day 1] Zero to MVP in 30 Days: Idea number 1

Migrating Elephants - How To Migrate Petabyte Scale Hadoop Clusters With Zero Downtime

Serving PHP on Apache HTTPD with PHP-FPM

PHP info

How to use Keras2 flow_from_directory() with Azure blob storage

Introduction to Containerized applications with Docker

Determining ROI for Your RPA Project

Ionic or Flutter: Which App Development Framework should you choose for your Next Project?

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
Dharesh Vadalia

Dharesh Vadalia

DevOps Engineer

More from Medium

UML class diagrams

Git:- Git is a distributed version control system for tracking changes in source code during…

DevOps in Web Development

Learning about GIT