Day 12   GitHub Cheat Sheet

Day 12 GitHub Cheat Sheet

Install

GitHub Desktop

desktop.github.com

Git for All Platforms

git-scm.com

Configuring Git

$ git config --global user.name "[name]"

Sets the name you want to be attached to your commit transactions.

$ git config --global user.email "[email address]"

Sets the email you want to beattached to your commit transactions.

$ git config --global color.ui auto

Enables helpful colorization of the command line output

$ git config –global alias

Creates a Git command shortcut

$ git config –system core.editor

Sets the preferred text editor

$ git config –global –edit

Open and edit the global configuration file in the text editor

Setting Up Git Repositories

$ git init [project-name]

Creates an empty repository in the project folder with the specified name

$ git clone (repo URL)

Downloads a project from a remote service such as Github and its entire version history 

$ git clone (repo URL) (folder)

Clones a repository to a specific folder

$ git remote -v

Displays a list of remote repositories with URLs

$ git remote rm (remote repo name)

Removes a remote repository

$ git fetch

Fetching from a repository grabs all the new remote-tracking branches and tags without merging those changes into your own branches.

$ git pull

Retrieve the most recent changes from origin and merge

Managing File Changes

$ git add (file name)

Adds file changes to staging. Snapshots the file in preparation for versioning.

$ git add 

Adds all directory changes to staging

$ git add -A

Adds new and modified files to staging

$ git rm (file_name)

Removes a file and stops tracking it. Deletes the file from the working directory and stages the deletion

$ git rm –cached (file_name)

Removes the file from version control but preserves the file locally

$ git checkout <deleted file name>

Recovers a deleted file and prepares it for commit

$ git status

Displays the status of modified files. Lists all new or modified files to be committed

$ git diff

Displays all unstaged changes in the index and the current directory. Shows file differences that are not yet staged

$ git diff --staged

Shows file differences between staging and the last file version.

$ git reset [file]

Unstages the file, but preserve its contents

$ git commit -m "[descriptive message]"

Records file snapshots permanently in version history

$ git mv [file-original] [file-renamed]

Changes the file name and prepares it for commit

REDO COMMITS

Erase mistakes: You would typically want to UNDO/REDO when you commit some changes to Git and realize that the changes need to be removed/reverted.

$ git reset [commit]

Undo all commits after [commit], preserving changes locally

$ git reset --hard [commit]

Discards all history and changes back to the specified commit

GROUP CHANGES: Commands for Git branching

You can decide how to group the changes to create meaningful commits.

$ git branch

Lists all local branches in the current repository

$ git branch [branch-name]

Creates a new branch

$ git checkout [branch-name]

Switches to the specified branch and updates the working directory

$ git merge [branch]

Combines the specified branch’s history into your current branch

$ git branch -d [branch-name]

Deletes the specified branch

$ git fetch remote <branchname>

Fetches a branch from the repository

$ git push –all

Pushes all local branches to a designated remote repository

SAVE FRAGMENTS

The Git stash command removes changes from your index and “stashes” them away for later. It is useful if you wish to pause what you are doing and work on something else for a while. You cannot stash more than one set of changes at a time.

$ git stash

Temporarily stores all modified tracked files

$ git stash pop

Restores the most recently stashed files

$ git stash list

Lists all stashed changesets

$ git stash drop

Discards the most recently stashed changeset

Installing on Linux

If you want to install the basic Git tools on Linux via a binary installer, you can generally do so through the package management tool that comes with your distribution. If you are on operating systems such as Fedora you can use dnf.

$ sudo dnf install git-all

 

If you are on a Debian-based distribution, such as Ubuntu use the following command

$ sudo apt install git-all

Installing on macOS

There are several ways to install Git on a Mac. The easiest way is to install it from the Github website

https://mac.github.com

Installing on Windows

There are also a few ways to install Git on Windows. The most official build is available for download on the Git website. 

https://git-scm.com/download/win

Thank you for reading ,