Skip to content

Instantly share code, notes, and snippets.

@dmynerd78
Last active August 30, 2020 22:29
Show Gist options
  • Save dmynerd78/f0032d4925192009b288139563923976 to your computer and use it in GitHub Desktop.
Save dmynerd78/f0032d4925192009b288139563923976 to your computer and use it in GitHub Desktop.
Git Cheatsheet

Git Usage

This cheat sheet is not for beginners learning Git. Instead, it is a simple "here's all the most used commands" for when you inevitably forget one or two.

Table of Contents

Basics

You should really know this already. I added it just to cover all the frequently used commands

Initialize git repo

git init

Get remote meta-data

NOTE: This does not actually download said changes

git fetch

Download remote changes

git pull

Clone remote repository

git clone <url>

Check changes

git status

Stage all changes

git add .

Commit all changes

git commit -m "Comment"

Stash changes for later

git stash

Restore stashed changes

git stash pop

Config Stuff

To see all available config options refer to the git config documentation

Update git username

git config --global user.name "username"

Update git email

If using GitHub, you can use the noreply email <username>@users.noreply.github.com

git config --global user.email "email@example.com"

Branching

For more information check out git-scm.com's branch and merging page

Create a new branch

git checkout -b my-new-branch

Pushing a newly created branch

-u can also be used instead of --set-upstream

git push --set-upstream <upstream> my-new-branch

Typically, <upstream> is origin

Switch to pre existing branch

git checkout my-branch

Merge branch into another branch

This will take the changes in your current branch and merge them with branch-to-merge-into

git merge branch-to-merge-into

Get list of remote branches

git fetch

Large File Storage (LFS)

Used to store large files separately from remote repo. See here for more info

Install LFS

git lfs install

Track file type

This tracks all .psd files.

git lfs track "*.psd"

This causes the .gitattributes to be updated. Add this to the repo via

git add .gitattributes

Submodules

Information obtained from here

Adding a submodule

git submodule add git@github.com:url_to/my-submodule.git repo-path-to-submodule

Pushing changes for a submodule

cd into said module and use regular git commands

Update submodule

git submodule update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment