# Git Cheat Sheet / Guide

[https://ittools.fifthdread.com/git-memo](https://ittools.fifthdread.com/git-memo)

#### Install Git on MacOS

  
`brew install git`


#### Install Git on Windows

[https://git-scm.com/download/win](https://git-scm.com/download/win)

#### Set Config

```shell
git config --global user.name "[name]"
git config --global user.email "[email]"
```

example:

```shell
git config --global user.name "testuser"
git config --global user.email "email@emailtest.com"
```

#### Set Editor to nano on MacOS

```lisp
git config --global core.editor "nano"
```

```lisp
export GIT_EDITOR=nano
```

```lisp
export VISUAL=nano
export EDITOR="$VISUAL"
```

#### Generate SSH Key

On Windows

```lisp
ssh-keygen.exe -t rsa -b 4096
```

On MacOS / Linux

```lisp
ssh-keygen -t rsa -b 4096
```

Press Enter - No Passphrase, leave empty

#### Take public key and add into Gitea

Key is located in /Users/&lt;username&gt;/.ssh  
  
Take id\_rsa.pub - Open in text editor. Copy contents.  
  
Go to profile on Gitea HERE: [https://gitea.fifthdread.com/user/settings/keys](https://gitea.fifthdread.com/user/settings/keys)

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/X6gimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/X6gimage.png)

Add Key  
  
Paste public key information into Content Box.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/tzqimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/tzqimage.png)

It should auto-complete the Key Name. Click Add Key to complete.  
  
Your machine can now trusted to access the Git Repository via SSH. You can now pull and push to the repo.

#### Cloning a project / Pulling a Project

To Clone a project from the repo, go to the project on gitea.

Switch to SSH and click the Copy button to copy the SSH access URL.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/Xgwimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/Xgwimage.png)

Navigate to the directory you want to clone your project into. In the example below, I go to a ProjectFiles folder.

Type git clone "URL" "DirectoryName"

```lisp
git clone <PASTE URL HERE> <BRANCH NAME HERE>
```

The branch name is not required. It is simply the name of the directory you are going to use for the files. I like to stay organized and make it the name of the branch.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/R8Vimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/R8Vimage.png)

it will now download the repo.

#### Renaming your local git branch  


This is important, as if you do not rename your branch prior to pushing it to the repo, it will override the main branch. Not good!  
  
Check what branch you are on, and what the branch name is:

```
git branch
```

  
Rename Main branch to something else via the below command:

```
git branch -m <NAME>
```

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/ttcimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/ttcimage.png)

####   
Branches  


To upload changes to a project, make sure you are working on a separate branch- RENAME YOUR BRANCH

  
Never upload directly to the main branch on a collaborative project, as branch merges need to be reviewed by the team prior to being merged.

#### Committing Changes

First verify you have renamed the Branch

```
git branch
```

If it is something other than main, we can proceed.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/9x8image.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/9x8image.png)

  
To see the changes you made since the repo was pulled, type:

```
git diff
```

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/c50image.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/c50image.png)

Commit the changes with the following command:

```
git commit -a
```

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/Kvyimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/Kvyimage.png)

  
The NANO editor will appear if on MacOS, or your preferred editor on Windows, such as Notepad++. Edit the top of the document with your commit comments. Save when complete.

If you opened in VIM and not nano, it looks like this... ew. Don't ask me how VIM works.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/krhimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/krhimage.png)

This is what it should look like if NANO opens the file.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/RAeimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/RAeimage.png)

CTRL+X to exit, and yes to save

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/Tytimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/Tytimage.png)

This indicates success.  
  
  
To check the status of your branch.

```
git status
```

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/rUMimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/rUMimage.png)

#### Uploading your new Branch / Pushing Changes

Again, make sure you aren't on main branch.

```
git branch
```

Now type in the following to upload your changes!

```
git push origin HEAD
```

This will upload a branch based off the name defined in "git branch"

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/H06image.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/H06image.png)

Alternatively, define a branch name in the command.

```
git push origin HEAD:branchtestname
```

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/u7Jimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/u7Jimage.png)Done!

#### Looking at different branches on Gitea

Go to Branches. Click on New Branch from Main.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/zImimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/zImimage.png)

In this example, I made a test branch called another\_mac\_test

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/nKvimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/nKvimage.png)

See how it is selected here- it shows "another\_mac\_test" indicating we are viewing the new branch.

#### Submit Pull Request - Merge with Main  


When you have made changes and want to pull them into the main branch. Open Gittea, go to branches, and click New Pull Request on your branch.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/pHGimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/pHGimage.png)

You will open a pull request with all your changes outlined. Click on New Pull Request again.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/6bJimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/6bJimage.png)

You will now comment on the pull request, then click Create Pull Request.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/jkUimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/jkUimage.png)

The request will now be reviewed.

####   
  
  
Approve Pull Requests  


Pull Requests must be reviewed prior to merging. You can see the "1" indicating 1 request is waiting for review.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/kmQimage.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/kmQimage.png)

  
Clicking on Pull Requests shows the waiting requests.

[![image.png](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/HH6image.png)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/HH6image.png)

This pull request can now be reviewed and merged.

[![Screenshot 2023-09-25 at 1.16.15 PM.jpg](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/scaled-1680-/screenshot-2023-09-25-at-1-16-15-pm.jpg)](https://wiki.fifthdread.com/uploads/images/gallery/2023-09/screenshot-2023-09-25-at-1-16-15-pm.jpg)

The branch can also be deleted after it is merged with the main branch successfully.  
  
You're done!