My First GitHub Commit: A Simple Guide for Beginners

When I first started coding, I didn’t know GitHub at all — but in today’s world, it’s basic knowledge you must have. So I went after it. This is how I pushed my first code to GitHub.

In this post, I’m just sharing my first time pushing to GitHub — what errors I faced and what commands I used.

GitHub
We code on our computers — but what if our computer crashes, gets stolen, or our files get accidentally deleted? With GitHub, our work stays safe on their cloud system. Small and big companies use GitHub for version control and history.

At first, I didn’t know that you have to initialize your local project folder as a Git repo, so I got this line:

“'git' is not recognized as an internal or external command”

When I ran this command in the terminal — git init — here’s what happened:

When I ran git init, my terminal called the Git program, but my computer didn’t have it. So I downloaded GitHub.

https://git-scm.com/downloads/win

Git Terminal

MINGW64 ~— This means now I’m in Git Bash and in my home directory. Then I typed this to go to the folder where I saved my project:

cd /c/Users/main folder /your project folder

This means I’m now inside my project folder — after MINGW64 I can see my folder name

MINGW64 ~/my project folder

I wanted to check if I was in the right folder, so I typed -ls- in Bash and I saw my files:

main.py,requirements.txt

Then I typed git init means Initialize this folder as a Git repository

If it worked, I saw:

Initialized empty Git repository in cd /c/Users/main folder /your project folder/.git/

This means the folder is initialized. I can see I’m on the master branch: MINGW64 ~/my project folder (master)

The git init command creates a hidden .git directory in my project folder. Now this is officially a Git repository — I can track my file versions.

Without git init, there’s no .git folder — so Git commands like status, commit, or push won’t work.

OK, now I’m in MINGW64 ~/my project folder (master), I can start adding files with git add., and commit them. This creates my first snapshot — the starting point in my new Git repository. A commit is like a project snapshot at that point in time for version control.

git commit -m "Initial commit: setup project structure"

Project structure means: I include my basic project files — requirements.txt, README, etc.

This command creates the first official save point in my Git repository’s history.

Then I got this: “Author identity unknown” — it means Git needs to know who I am (my identity) for the commit history. So, to set my username and email, I ran these commands with my user and email. This is normal when you use Git for the first time on your computer or on a new computer.

git config --global user.name "username"
git config –global user.email"your_email"

$ ^[[200~git config --global user.name "myusername"

bash: $'\E[200~git': command not found. It means my first command worked fine, but the second one — $'\E[200~git' — was a glitch. This happened because the terminal pasted extra invisible characters. So, I ran these git config commands one by one again. Then I typed this

git config—global –list To check if it was done or not, I ran this command and it worked. Git returned

user.name\=myusername

user.email=myemail@gmail.com

Then I ran the commit command again.

git commit -m "Initial commit: setup project structure"

And it returned:

[master (root-commit) e295662] It means I’m on the (master branch) and I’ve created the very first commit in this repository.

Now, to connect my local repository to the remote repository hosted on GitHub, I ran this command:

git remote add origin

https://github.com/username/projectfolder

And when we run git init, Git names the local (branch master) by default. But these days, many projects use main instead. So the problem is: if my local branch name is master and my remote repository wants main, then my push can fail or create two separate branches (master and main) instead of one. So I need to rename master to main.

So I ran this command:

$ git branch -M main. But when I ran it, I got this error

Error! [rejected] main -> main (fetch first)

error: failed to push some refs to 'https://github.com/username/my project folder

hint: Updates were rejected because the remote contains work that you do not

hint: have locally. This is usually caused by another repository pushing to

hint: the same ref. If you want to integrate the remote changes, use

hint: 'git pull' before pushing again.

hint: See the 'Note about fast-forwards' in 'git push— help' for details.

It means my local branch main tried to push to the remote branch main, but my remote branch already had some commits that my local branch didn’t have. So Git stopped me from overwriting files. To fix this, I pulled and rebased them.

$ git pull --rebase origin main

This means I got the latest commits from the main branch on the origin remote, and reapplied my local commits on top of them, one by one. This keeps the commit history neat and avoids extra merge commits.
Then I ran this command:

$ git push -u origin main And it returned the remote repository address, which included the official GitHub URL, my username, and my project name.

$ To https://github.com/username/my project folder name

branch 'main' set up to track 'origin/main'.

Now

Push successful! My code now lives at that GitHub link.
This is how I pushed my code to GitHub for the first time. I learned so many new things along the way, so I thought I should share it online — because there are so many students like me learning this in their college life too

0
Subscribe to my newsletter

Read articles from Najmussahar kazmi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Najmussahar kazmi
Najmussahar kazmi