# 🤓 Git & Github Set Up

### What is git?

Local version control system

### What is github?

Online public repository

[elpepebenitez - Overview](https://github.com/elpepebenitez)

### Setting up

Make sure that your operating system is updated!

- Install Git

Depending on your operating system you install or upgrade git differently, so follow the steps in the link below until you have an updated git version

[Setting Up Git | The Odin Project](https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/setting-up-git)

```
git --version
```

- Configure Git

```
git config --global user.name "Your Name"
git config --global user.email "yourname@example.com"
```

Set default branch to main

```
git config --global init.defaultBranch main
```

Enable colorful output 

```
git config --global color.ui auto
```

See if you already have a SSH key

```
ls ~/.ssh/id_rsa.pub
```

- Generate a SSH key

```
ssh-keygen -C <youremail>
```

When it prompts you for a location to save the generated key, just push `Enter`.

Next, it will ask you for a password; enter one.

```
cat ~/.ssh/id_rsa.pub
```

- Configure Github

After you created your github account, follow these steps:

1. Copy that text from `ssh` to the end of your email address
2. Go to [github.com/settings/ssh](https://github.com/settings/keys)
3. Click on the green button `New SSH key`
4. Fill in the Title with your computer name (`Macbook Pro` for instance)
5. Paste the **key**
6. Finish by clicking on the **Add SSH key** green button.

Check that it worked

```
ssh -T git@github.com
```

### Useful git commands

[Introduction to Git | The Odin Project](https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/introduction-to-git)

[https://rogerdudler.github.io/git-guide/files/git_cheat_sheet.pdf](https://rogerdudler.github.io/git-guide/files/git_cheat_sheet.pdf)

### Basic commands

Two ways to get a folder:

- Clone it

```
git clone
```

- Make your own folder

```
git init
```

Other useful commands

```
git status → tells you what is going on right now inside of your folder

git add → adds the file that you want to save. Changes start being tracked. 

git commit → saves the file or files added. You also put a -m " " to put a message explaining your changes

git log → shows you all the commit history in the folder

gst → git status shortcut

git diff → You can see the differences between your last version and your current uncommited version

git add . → adds the whole folder with all the files that have been changed
```

**Remote** basically means somewhere else than your computer where you can save your work. It could be github or any other platform. 

```
git remote -v tells us the links that any folder or file has 
```

**Fork** is when you take a folder in github and you make a copy on your online profile. You do it online. 

**Clone** means that you downloaded that folder into your computer

```
git clone + ssh key → you take the ssh key from your git hub profile and you use it to clone a repository to yout computer
```

**Push** is the command to save your work remotely

```
git push origin main → origin is the nickname of the github repo and main is the main branch
```

**Pull** brings the changes online to your computer to update the folder or file where you are working

```
git pull origin main

git reset HEAD → undoes last command
```
