# Put your code in a git repository

> Source: https://www.allsweb.com/sixpanel/docs/put-your-code-in-git
> Markdown for agents: https://www.allsweb.com/sixpanel/docs/put-your-code-in-git.md
> Publisher: AllsWeb (www.allsweb.com)

Part of: SixPanel documentation

**What this page is for.** Turn the 6ammart file you downloaded from CodeCanyon into a private git repository, so SixPanel can install from it and update it later with one button.

**You need**

- The 6ammart file you bought on CodeCanyon, unzipped on your own computer.
- A free account on GitHub, GitLab or Gitea. This page uses GitHub. The other
  two work the same way, with different button names.
- About twenty minutes. You do this once.

---

## Do you have to do this?

No. SixPanel installs your 6ammart code **either** from a git repository
**or** from the CodeCanyon zip you already have — both are on the **Deploys**
page, side by side, and the zip path needs nothing on this page.

Git is still worth the twenty minutes, because it is what makes the rest of
this manual work:

- **Get the latest code** brings a new version to the live server with one
  button press, showing you exactly what changed first.
- **Roll back** puts the last working version back. "The last version" only
  means something when there is a history.
- **Automatic deploys** can update the server every time you push.

A project installed from a zip is updated by uploading the next zip, which
works and is honest about what it costs: you see less of what changed, and
there are no automatic deploys.

---

## The repository must be private

> **Decide this before you create anything** — the repository must be
> **private**. You cannot undo making one public. People and search engines
> copy public code within minutes, and making it private again does not take
> those copies back.

Two reasons:

- The 6ammart code is licensed to **you**. A public repository hands it to
  everybody, and that breaks the licence you paid for.
- 6ammart carries a settings file named `.env`. People add mail passwords and
  payment keys to that file and send it to the repository without noticing. In
  a private repository that is a mistake you can fix. In a public one it is a
  leak.

Every step below keeps the repository private. Check the setting twice.

---

## 1. Find the Laravel root

This is the step people get wrong, and a wrong folder here breaks the install
later.

Unzip what you downloaded. Inside there are usually several folders: the admin
code (Laravel), the customer website (React), the mobile apps, and
documentation.

Open them until you find the folder that holds a file named **artisan**. Next
to `artisan` you also see folders named `app`, `config`, `public` and
`routes`. That folder is the **Laravel root**. It is the only part SixPanel
installs.

`artisan` must end up at the **top** of your repository, not inside a folder
inside it. If SixPanel downloads your repository and finds no `artisan`, the
install fails.

## 2. Leave out what does not belong

Look inside the Laravel root for a folder named `vendor`. It holds thousands of
library files. SixPanel installs those on the server by itself, so they do not
belong in the repository.

Create a file named `.gitignore` in the Laravel root, holding these two lines:

```
/vendor
/node_modules
```

If the Laravel root already has a `.gitignore`, open it and make sure both
lines are in it. Files whose name starts with a dot are hidden by default. In
Notepad, choose **File** → **Save as**, set **Save as type** to **All Files**,
and type the name with quotation marks: `".gitignore"`. On Mac, press
**Command+Shift+.** in Finder to show hidden files.

GitHub refuses any single file bigger than 100 MB. Nothing in a normal Laravel
root is that big once `vendor` is left out. If a push is refused because of a
large file, remove that file from the folder and send it again.

---

## 3a. Create the repository — GitHub Desktop

This way needs no commands.

1. Open `https://github.com` and sign in. Create a free account if you have
   none.
2. Download **GitHub Desktop** from `https://desktop.github.com` and install
   it.
3. Open GitHub Desktop and sign in with the same account.
4. Choose **File** → **New repository…**
5. Set **Name** to `6ammart-admin`. Set **Local path** to any folder on your
   computer. Leave the other boxes as they are. Press **Create repository**.
6. Open the folder it made: **Repository** → **Show in Explorer** on Windows,
   or **Repository** → **Show in Finder** on Mac.
7. Copy **everything inside your Laravel root** into that folder, `artisan`
   included. Copy the contents, not the Laravel root folder itself. When you
   are finished, `artisan` sits directly in the new folder.
8. Go back to GitHub Desktop. The list on the left fills with your files. Type
   `first import` in the **Summary** box at the bottom left, then press
   **Commit to main**.

> **Read this before the last step** — the last step sends your code to
> GitHub, and that cannot be taken back. In the box that opens, **Keep this
> code private** must stay ticked. If you publish it public by mistake, delete
> the repository at once and make a new one — but treat the code as seen by
> others.

**Last step.** Press **Publish repository** at the top. In the box, check that
**Keep this code private** is ticked, then press **Publish repository**.

## 3b. Create the repository — the terminal

Use this instead of the section above if you prefer commands.

First make the empty repository on GitHub:

1. On `https://github.com`, press **+** at the top right, then **New
   repository**.
2. Set **Repository name** to `6ammart-admin`.
3. Choose **Private**.
4. Do not tick anything under **Initialize this repository with**.
5. Press **Create repository**.

Then open a terminal **in your Laravel root** — the folder that holds
`artisan` — and run these five commands:

```bash
git init -b main
git add .
git commit -m "first import"
git remote add origin https://github.com/YOUR-NAME/6ammart-admin.git
git push -u origin main
```

Replace `YOUR-NAME` with your GitHub user name. The last command asks you to
sign in.

---

## 4. Copy the address SixPanel needs

Open your repository page on GitHub. Press the green **Code** button and choose
**HTTPS**. The address looks like this:

```
https://github.com/YOUR-NAME/6ammart-admin.git
```

That address goes into **Git repository URL** in the panel. The branch is
`main`.

Use the `https://` address for the first install. The panel signs in with an
access token you paste once; the next section explains what happens after that.

---

## 5. How SixPanel signs in to a private repository

There are two moments, and they are answered differently.

### The first install: an access token you paste once

Make a token on GitHub: **Settings** → **Developer settings** → **Personal
access tokens**. Give it read access to this one repository and nothing else.
Paste it into **Access token** on the **Deploys** page.

SixPanel puts the token into the download address for that one command, then
writes the plain address back. **The token is not kept on the server.** That is
deliberate: a token stored on a server is a token that can leak from it.

### Every deploy after that: a read-only key the panel makes itself

Because the token is not kept, the server needs its own way in for later pulls
and for automatic deploys. The panel issues one:

1. Open **Deploys** and start **Set up automatic deploys** (or open the read
   access card on the repository's section).
2. Press **Create the key**. The panel generates a **read-only SSH key for this
   one repository**, keeps the private half in its own data directory where
   only root can read it, and shows you the public half.
3. Copy that public half into your repository: GitHub → **Settings** → **Deploy
   keys** → **Add deploy key**. Give it any title. **Leave "Allow write access"
   OFF.**
4. Press **Check again**. The panel tries a real read against your repository
   and tells you whether it worked.

What that buys you, compared with leaving a token on the server:

- it can **only read** — a leak cannot rewrite your code;
- it is scoped to **one repository**, not to your whole account;
- you can revoke it from that repository's own settings page, per server,
  without touching anything else;
- it is a key, not a bearer token, so pasting it into a support thread by
  accident gives nobody anything.

The admin app and the customer website each get their own key. **Replace the
key** issues a new one; the old one stops working immediately, so you have to
paste the new one in.

---

## How to check it worked

- The repository page on GitHub shows a **Private** label next to its name.
- The file list on that page shows `artisan` at the top level.
- There is no `vendor` folder in that list.
- **Code** → **HTTPS** gives an address that ends in `.git`.
- After the install, the read access card on the **Deploys** page shows
  **working**.

You are ready for **[Install your 6ammart code](https://www.allsweb.com/sixpanel/docs/install-app)**.

## If it went wrong

**GitHub Desktop lists tens of thousands of files**
The `.gitignore` from step 2 is missing, or it is not in the same folder as
`artisan`. Add it, and the list drops to a few thousand.

**The push was refused because a file is too large**
GitHub allows no single file over 100 MB. The message names the file. Remove it
from the folder and commit again. Files that big are almost always inside
`vendor` or `node_modules`, which step 2 leaves out.

**The panel's install cannot find `artisan`**
You copied the Laravel root folder instead of its contents, so `artisan` sits
one level down. Move everything up one level in the repository and commit
again.

**The clone step fails with a private repository**
A token only works with an `https://` address, and a private repository with no
token fails here. Paste a read token into **Access token** for the install.

**Update says it could not read the repository**
The server has no read access of its own yet. Create the deploy key in section
5 and paste it into the repository. That is the whole fix, and it takes two
minutes.

More causes and fixes: **[When something is broken](https://www.allsweb.com/sixpanel/docs/troubleshooting)**.
