# How to push your project to GitHub

I used to forget the steps to push my project inside my laptop to Github repository. Maybe because I rarely coding any projects, or I even tried to memorize the git commands instead to understand it.

However, I learned this in a fun way when I build personal vibe coding project in Cursor with the guidance from ChatGPT to help me understand what are those git commands for and how to push, commit, and initiate the new repository.

I wrote this in case I forget, and I always can back to read it again.

## Check before initiate

First, I opened the terminal inside my VS Code then check for GitHub CLI by run these commands:

```shell
git --version 
gh --version
```

Luckily I already installed GitHub CLI few months ago.

I learned that lets you create GitHub repositories directly from the terminal, but I don't know yet if my GitHub account already signed in here. So, I run this command again:

```shell
gh auth login
```

Then in terminal asks me to choose [github.com](http://github.com), HTTPS, and browser authentication when prompted. And before I continue uploading, ChatGPT suggested me to create or add this inside my `.gitignore` file:

```plaintext
# Dependencies
node_modules/

# Build output
dist/
build/

# Environment variables and secrets
.env
.env.*
!.env.example

# Logs
*.log
npm-debug.log*

# Local editor files
.vscode/
.idea/

# Operating system files
.DS_Store
Thumbs.db
```

I ensure my `.gitignore` file exists to **prevent unnecessary files, large folders, and sensitive information from accidentally being uploaded to GitHub.**

It keeps my repository clean, lightweight, secure, and easier to manage.

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><p>Remember to not upload API keys, authentication tokens, passwords, or private <code>.env</code> files. Including the images or videos if your repository is open for public.</p></div>
</div>

Once again I checked if my project already has Git initialized.

```shell
git status
git remote -v
```

## Create new repository

Apparently Git reports that my file is not a repository, so I had to initialize it.

```shell
git init
git branch -M main
```

After I ran that commands, my Git is already initialized and I checked `.env` to show me an existing remote, I already ensured it won't push to wrong repository. Yet, I didn't follow ChatGPT guidance.

```shell
git config --global user.name "YOUR_GIT_NAME"
git config --global user.email "YOUR_GIT_EMAIL"
```

I skipped this part where later I got a problem because I think my GitHub account already signed in within VS Code—I thought I didn't need to do that.

So, I quickly ran another commands where my files already exist.

```shell
git add .
git status
```

And created my first commit

```shell
git commit -m "chore: initial workflow UI implementation"
```

Then created an annotated version tag—to help me see the changelog. This means the changes belong to that Version 1.0.0

```shell
git tag -a v1.0.0 -m "Version 1.0.0 - Initial workflow UI baseline"
```

## Encounter the errors

After I made version tag `git tag -a v1.0.0 ...` successfully, I had errors because I made mistakes as I said earlier.

The `gh repo create ...` and `git push origin v1.0.0` were failed because GitHub CLI isn't authenticated and the `origin` remote doesn't exist yet. I don't need to restart Git initialization, recreate your commit, or create another tag.

Here's five steps I did to fix it:

### Step 1: Log in to GitHub

In the terminal I started to run this command again,

```shell
gh auth login
```

because apparently I hadn't log in any of my GitHub account yet, that's why I encountered the error in my command earlier. Then GitHub CLI shows this:

| Questions | Select |
| --- | --- |
| Where do you use GitHub? | [github.com](http://github.com) |
| Preferred protocol | HTTPS |
| Authenticate Git with GitHub credentials? | Yes |
| How would you like to authenticate? | Login with a web browser |

It displayed a one-time code and ask me to press Enter to open the browser to log in my GitHub account with the access tokens inside my terminal.

### Step 2: Verify my login

After completing my authentication, I did this

```shell
gh auth status
```

to see if I'm already logged in to [github.com](http://github.com)

### Step 3: Create new repository (again)

Since there's no repository uploaded on my Github when I checked my profile, I needed to run the same command again:

```shell
gh repo create workflow-ui-component --private --source=. --remote=origin --push
```

That should create a new private repository, link it as `origin`, and push your existing commits.

### Step 4: Push my Version 1.0.0 tag

Once the repository has been created successfully, I checked if it uploaded in my existing local version tag to GitHub

```shell
git push origin v1.0.0
```

### Step 5: Confirm everything worked

I confirmed all things work inside my project by running this command:

```shell
git status
git remote -v
git tag
```

Then open the repository:

```shell
gh repo view --web
```

I could now see my project on GitHub, including its commit history and `v1.0.0` tag. Further, I ran this:

```shell
gh auth login
```

Eventually I finally succeed creating the repository, but I found another problem I didn't expect, you can read here .

---

## Save for future versions

Since I used Antigravity to vibe code my project, I have to remind myself every changes there must be pushed to GitHub, so I can have checkpoint.

ChatGPT suggested after fixing one single component or element in styling I should run this command again to make a commit:

```shell
git add .
git commit -m "fix: refine workflow card styling and connector handles"
git push origin main
```

Then if I was ready to update next version:

```shell
git tag -a v1.1.0 -m "Version 1.1.0 - Workflow visual refinements"
git push origin v1.1.0
```

## Sources to learn more

1. [Git Guides - git init](https://github.com/git-guides/git-init)
2. [Git Init: How to Initialize and Set Up a Git Repository | DataCamp](https://www.datacamp.com/tutorial/git-init?utm_cid=19589720824&utm_aid=157156375831&utm_campaign=230119_1-ps-other~dsa-tofu~all_2-b2c_3-apac_4-prc_5-na_6-na_7-le_8-pdsh-go_9-nb-e_10-na_11-na&utm_loc=9125808-&utm_mtd=-c&utm_kw=&utm_source=google&utm_medium=paid_search&utm_content=ps-other~apac-en~dsa~tofu~tutorial~git&gad_source=1&gad_campaignid=19589720824&gbraid=0AAAAADQ9WsFaE-SVPwzkT-lK-z4AYgRs8&gclid=EAIaIQobChMI74uVj9uCmAMVPoZmAh24WBPSEAAYASAAEgK2HfD_BwE)
