← All cheat sheets

Git Command Line Cheat Sheet

Download our Git Command Line Cheat Sheet with commands for terminal tasks and Git workflows. Perfect for developers and data professionals.

← All cheat sheets

Git Command Line Cheat Sheet

Download our Git Command Line Cheat Sheet with commands for terminal tasks and Git workflows. Perfect for developers and data professionals.

Table of Contents

Command Line

Syntax for

How to use

Explained

Setting Environment Variables

export VAR=value

Sets an environment variable VAR to value.

Running Python Scripts

python script.py

Runs a Python script from the command line.

Printing Text

echo "Hello, World!"

Prints "Hello, World!" to the terminal.

Changing Directory

cd /path/to/directory

Changes the current directory to the specified path.

Listing Files

ls -l

Lists files in the current directory with detailed information.

Creating Directories

mkdir new_directory

Creates a new directory named new_directory.

Deleting Files

rm file.txt

Deletes the file named file.txt.

Copying Files

cp source.txt destination.txt

Copies source.txt to destination.txt.

Moving and Renaming Files

mv old_name.txt new_name.txt

Renames or moves old_name.txt to new_name.txt.

Viewing File Contents

cat file.txt

Displays the contents of file.txt.

Searching Text

grep "pattern" file.txt

Searches for "pattern" in file.txt.

Redirecting Output

command > file.txt

Redirects command output to file.txt.

Appending Output

command >> file.txt

Appends command output to file.txt.

Changing File Permissions

chmod 755 script.sh

Sets the permissions of script.sh to 755.

Checking Disk Usage

du -h

Displays disk usage in human-readable format.

Finding Files

find /path -name "filename"

Searches for files named "filename" in /path.

Running Python Modules

python -m script

Runs a Python module as a script.

Starting a Bash Shell

bash

Starts a Bash interactive shell.

Printing Columns with AWK

awk '{print $1}' file

Prints the first column of a file.

Filtering CSV Rows

csvgrep -c column -m value file.csv

Filters rows in a CSV file by column value.

Starting IPython Shell

ipython

Starts an IPython interactive shell.

Appending Text to File

echo "text" >> file.txt

Appends "text" to the end of file.txt.

Extracting CSV Columns

csvcut -c column file.csv

Extracts a specific column from a CSV file.

Getting CSV Statistics

csvstat file.csv

Provides statistics about a CSV file.


Git

Syntax for

How to use

Explained

Initializing a Repository

git init

Initializes a new Git repository.

Cloning a Repository

git clone URL

Clones a repository from a remote URL.

Checking Repository Status

git status

Displays the status of the working directory and staging area.

Adding Files to Staging

git add file.txt

Adds file.txt to the staging area.

Committing Changes

git commit -m "message"

Commits staged changes with a message.

Viewing Commit History

git log

Shows the commit history.

Creating a New Branch

git branch branch_name

Creates a new branch named branch_name.

Switching Branches

git checkout branch_name

Switches to the branch named branch_name.

Merging Branches

git merge branch_name

Merges branch_name into the current branch.

Adding a Remote Repository

git remote add origin URL

Adds a remote repository.

Pushing Changes to Remote

git push origin branch_name

Pushes changes to the remote repository.

Pulling Changes from Remote

git pull origin branch_name

Pulls changes from the remote repository.

Aborting a Merge

git merge --abort

Aborts a merge in progress.

Stashing Changes

git stash

Stashes changes in the working directory.

Applying Stashed Changes

git stash apply

Applies stashed changes.

Deleting a Branch

git branch -d branch_name

Deletes the branch named branch_name.

Mike Levy

Written by

Mike Levy

Mike is a life-long learner who is passionate about mathematics, coding, and teaching. When he's not sitting at the keyboard, he can be found in his garden or at a natural hot spring.

Join 1M+ data learners on Dataquest.

  1. 1

    Create a free account

  2. 2

    Choose a learning path

  3. 3

    Complete exercises and projects

  4. 4

    Advance your career