Skip to main content

Git Cheat Sheet


Git is the free and open source distributed version control system that's responsible for everything GitHub related that happens locally on your computer. This cheat sheet features the most important and commonly used Git commands for easy reference.

SETUP

set a name that is identifiable for credit when review version history.

 git config --global user.name “[firstname lastname]”  

set an email address that will be associated with each history maker.

 git config --global user.email “[valid-email]”  

set automatic command-line colouring for Git for easy reviewing.

 git config --global color.ui auto  

SETUP & INIT

initialize an existing directory as a Git repository

 git init  

Retrieve an entire repository from a hosted location via URL.

 git clone [url]  

STAGE & SNAPSHOT

Show modified files in working directory, staged for your next commit.

 git status  

Add a file as it looks now to your next commit.

 git add [file]  

Unstage a file while retaining the changes in working directory.

 git reset [file]  

Diff of what is changed but not staged.

 git diff  

Diff of what is staged but not yet committed.

 git diff --staged  

Commit your staged content as a new commit snapshot.

 git commit -m “[descriptive message]”  

BRANCH & MERGE

List your branches. A * will appear next to the currently active branch.

 git branch  

Create a new branch at the current commit.

 git branch [branch-name]  

Switch to another branch and check it out into your working directory

 git checkout  

Merger the specified branch's history into the current one.

 git merge [branch]  

Show all commits in the current branch's history.

 git log  

INSPECT & COMPARE

Show the commit history for the currently active branch.

 git log  

Show the commits on branchA that are not on branchB

 git log branchB..branchA  

Show the commits that changed file, even across renames.

 git log --follow [file]  

Show the diff of what is in branchA that is not in branchB

 git diff branchB...branchA  

Show any object in Git in human readable format

 git show [SHA]  

TRACKING PATH CHANGES

Delete the file from project and stage the removal for commit.

 git rm [file]  

Change an existing file path and stage the move.

 git mv [existing-path] [new-path]  

Show all commit logs with indication of any paths that moved.

 git log --stat -M  

REWRITE HISTORY

Apply any commits of current branch ahead of specified one.

 git rebase [branch]  

Clear staging area, rewrite working tree from specified commit

 git reset --hard [commit]  

SHARE & UPDATE

Add git URL as an alias

 git remote add [alias] [url]  

Fetch down all the branches from that Git remote

 git fetch [alias]  

Merge a remote branch into your current branch to bring it up to date.

 git merge [alias]/[branch]  

Transmit local branch commits to the remote repository branch

 git push [alias] [branch]  

Fetch and merge any commits from the tracking remote branch.

 git pull  

TEMPORARY COMMITS

Save modified and staged changes.

 git stash  

List stack-order of stashed file changes

 git stash list  

Write working from top of stash stack

 git stash pop  

Discard the changes from top of stash stack

 git stash drop  

IGNORING PATTERNS

Save a file with desired patterns as .gitignore with either direct string matches or wildcard globs.

 logs/  
 *.notes  
 pattern*/  

System wide ignore pattern for all local repositories.

 git config --global core.excludesfile [file]  

The cheat sheet can be downloaded here.

ORIGINAL SOURCE

Comments

  1. this is very informative and will be of use

    at least I will have somewhere to refer to when am stuck

    ReplyDelete

Post a Comment

Your input is valued. Please type something....

Popular posts from this blog

Fun Terminal Commands Every Linux User Should Try

Accessing Maps from the terminal with MapSCII Requirements Telnet installed Internet Connection Firewall is disabled You can do this on Linux, Unix, Mac OS X or Windows with an app like PuTTY or the Windows 10 Linux bash shell or any Os that supports telnet. Open terminal and write the command below. telnet mapscii.me Hit enter and you're ready to browse and enjoy MapSCII. Navigate using the keyboard or mouse. Use the following keys on your keyboard Arrow keys: up, down, right, left A to zoom in Z to zoom out C toggles ASCII mode on/off You can also click and drag and hold on the map with your cursor. If your connection dropped without a reason, reconnect with telnet -E mapscii.me and use only cursors, A and Z to navigate. The Mapscii project is open source and you can install it locally if you'd like. Check out their project here on GitHub . The Dancing ASCII Party Parrot Requirements Curl installed Internet

SQL for Data Analysis - Udacity

  Entity Relationship Diagrams An  entity relationship diagram  (ERD) is a common way to view data in a database. Below is the ERD for the database we will use from Parch & Posey. These diagrams help you visualize the data you are analyzing including: The names of the tables. The columns in each table. The way the tables work together. You can think of each of the boxes below as a spreadsheet. What to Notice In the Parch & Posey database there are five tables (essentially 5 spreadsheets): web_events accounts orders sales_reps region You can think of each of these tables as an individual spreadsheet. Then the columns in each spreadsheet are listed below the table name. For example, the  region  table has two columns:  id  and  name . Alternatively the  web_events  table has four columns. The "crow's foot" that connects the tables together shows us how the columns in one table relate to the columns in another table. In this first lesson, you will be learning the bas

Impressive - Check if Your Email Address Has Been Hacked - Free,Easy Tutorial

haveibeenpwned.com Data breaches are rampant and many people don't appreciate the scale or frequency with which they occur. A "breach" is an incident where data is inadvertently exposed in a vulnerable system, usually due to insufficient access controls or security weaknesses in the software. How is the legitimacy of a data breach established? Attackers often give "breach" announcements, which are later revealed to be hoaxes. There is a delicate balance to be struck between making data searchable as soon as possible and conducting proper due diligence to confirm the breach's validity. In order to verify the authenticity of a violation, the following steps are normally taken: Has the affected provider made a public statement about the security breach? Does the information stolen in the breach show up in a Google search (i.e., it was simply copied from another source)? Is the structure of the data consistent with what you'd expect to see in a breach? Have