# GIT

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.

Link to the original PDF cheat sheet file [here](https://education.github.com/git-cheat-sheet-education.pdf).

***

### INSTALLATION & GUIS

With platform specific installers for Git, GitHub also provides the ease of staying up-to-date with the latest releases of the command line tool while providing a graphical user interface for day-to-day interaction, review, and repository synchronization.

**GitHub for Windows** <https://windows.github.com>

**GitHub for Mac** <https://mac.github.com>

For Linux and Solaris platforms, the latest release is available on the official Git web site.

**Git for All Platforms** <http://git-scm.com>

***

### SETUP

Configuring user information used across all local repositories.

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">git config --global user.name “[firstname lastname]”
</code></pre></td><td>set a name that is identifiable for credit when review version history</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git config --global user.email “[valid-email]”
</code></pre></td><td>set an email address that will be associated with each history marker</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git config --global color.ui auto
</code></pre></td><td>set automatic command line coloring for Git for easy reviewing</td></tr></tbody></table>

***

### SETUP & INIT

Configuring user information, initializing and cloning repositories.

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">git init
</code></pre></td><td>initialize an existing directory as a Git repository</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git clone [url]
</code></pre></td><td>retrieve an entire repository from a hosted location via URL</td></tr></tbody></table>

***

### STAGE & SNAPSHOT

Working with snapshots and the Git staging area.

<table><thead><tr><th>Commands</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">git status
</code></pre></td><td>show modified files in working directory, staged for your next commit</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git add [file]
</code></pre></td><td>add a file as it looks now to your next commit (stage)</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git reset [file]
</code></pre></td><td>unstage a file while retaining the changes in working directory</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git diff
</code></pre></td><td>diff of what is changed but not staged</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git diff --staged
</code></pre></td><td>diff of what is staged but not yet commited</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git commit -m “[descriptive message]”
</code></pre></td><td>commit your staged content as a new commit snapshot</td></tr></tbody></table>

***

### BRANCH & MERGE

Isolating work in branches, changing context, and integrating changes.

<table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">git branch
</code></pre></td><td>list your branches. a * will appear next to the currently active branch</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git branch [branch-name]
</code></pre></td><td>create a new branch at the current commit</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git checkout
</code></pre></td><td>switch to another branch and check it out into your working directory</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git merge [branch]
</code></pre></td><td>merge the specified branch’s history into the current one</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git log
</code></pre></td><td>show all commits in the current branch’s history</td></tr></tbody></table>

***

### INSPECT & COMPARE

Examining logs, diffs and object information.

<table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">git log
</code></pre></td><td>show the commit history for the currently active branch</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git log branchB..branchA
</code></pre></td><td>show the commits on branchA that are not on branchB</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git log --follow [file]
</code></pre></td><td>show the commits that changed file, even across renames</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git diff branchB...branchA
</code></pre></td><td>show the diff of what is in branchA that is not in branchB</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git show [SHA]
</code></pre></td><td>show any object in Git in human-readable format</td></tr></tbody></table>

***

### TRACKING PATH CHANGES

Versioning file removes and path changes.

<table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">git rm [file]
</code></pre></td><td>delete the file from project and stage the removal for commit</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git mv [existing-path] [new-path]
</code></pre></td><td>change an existing file path and stage the move</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git log --stat -M
</code></pre></td><td>show all commit logs with indication of any paths that moved</td></tr></tbody></table>

***

### IGNORING PATTERNS

Preventing unintentional staging or committing of files.

<table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">logs/ .notes pattern/
</code></pre></td><td>Save a file with desired paterns as .gitignore with either direct string matches or wildcard globs.</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git config --global core.excludesfile [file]
</code></pre></td><td>system wide ignore patern for all local repositories</td></tr></tbody></table>

***

### SHARE & UPDATE

Retrieving updates from another repository and updating local repos.

<table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">git remote add [alias] [url]
</code></pre></td><td>add a git URL as an alias</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git fetch [alias]
</code></pre></td><td>fetch down all the branches from that Git remote</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git merge [alias]/[branch]
</code></pre></td><td>merge a remote branch into your current branch to bring it up to date</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git push [alias] [branch]
</code></pre></td><td>Transmit local branch commits to the remote repository branch</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git pull
</code></pre></td><td>fetch and merge any commits from the tracking remote branch</td></tr></tbody></table>

***

### REWRITE HISTORY

Rewriting branches, updating commits and clearing history.

<table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">git rebase [branch]
</code></pre></td><td>apply any commits of current branch ahead of specified one</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git reset --hard [commit]
</code></pre></td><td>clear staging area, rewrite working tree from specified commit</td></tr></tbody></table>

***

### TEMPORARY COMMITS

Temporarily store modified, tracked files in order to change branches.

<table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash"><code class="lang-bash">git stash
</code></pre></td><td>Save modified and staged changes</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git stash list
</code></pre></td><td>list stack-order of stashed file changes</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git stash pop
</code></pre></td><td>write working from top of stash stack</td></tr><tr><td><pre class="language-bash"><code class="lang-bash">git stash drop
</code></pre></td><td>discard the changes from top of stash stack</td></tr></tbody></table>

{% embed url="<https://media.giphy.com/media/a7oVsf3WTOaoE/giphy.gif>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fastiraz.gitbook.io/doc/documentations/cheat-sheet/git.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
