PrimLagicPrimLagic

Git and GitHub for beginners: from the first commit to push

By Ali Abdollahi · · 2 min read

Git keeps the history of your files' changes. With it you can go back to a previous version, work on an idea without fear of breaking the main code, and collaborate with others. GitHub is a service that hosts Git repositories online. Here is the simplest path, step by step.

Install and configure once

Install Git from the official site and set your name and email once (they show next to every change in history):

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

Create a repo and make the first commit

Inside the project folder:

git init
git add .
git commit -m "first version"

git add stages the changes you want in the next commit; git commit records a snapshot of them in history. Write commit messages short and clear — your future self will thank you.

See status and history

git status
git log --oneline

Branches: change without risk

Create a branch for every new feature so the main branch stays healthy:

git switch -c feature-new
# ... make changes and commit ...
git switch main
git merge feature-new

If your repo's main branch is called master, use that instead of main.

Connect to GitHub

1. Create an empty repository on GitHub. 2. Point your local repo at it and push:

git remote add origin https://github.com/USERNAME/REPO.git
git push -u origin main

After that, git push sends new changes and git pull fetches other people's changes.

.gitignore: what should never enter the repo

Create a file named .gitignore and list the files and folders that must not be tracked:

node_modules/
dist/
.env

This is the most important security rule: never commit passwords, API keys or the .env file. In a public repo everyone can read them, and deleting the file in a later commit is not enough — it stays in history. If it happens, rotate the key immediately (more on env files).

Common beginner mistakes

  • Committing with no message, or a message that just says "changes".
  • One giant commit for ten unrelated jobs; one commit per job is better.
  • Working directly on the main branch in a team project.
  • Committing huge generated folders like node_modules.
  • Being afraid of git status — run it often; it only reads and breaks nothing.

What to learn next

Pull Requests on GitHub for reviewing changes, resolving conflicts during a merge, and git revert to undo a commit without erasing history. You can see real published code on Ali Abdollahi's GitHub.

Common questions

Are Git and GitHub the same thing? No. Git is the tool; GitHub is one of the services that hosts Git repositories (GitLab and Bitbucket are others).

I committed something by mistake — what now? A local commit that has not been pushed can be amended. Once pushed, do not rewrite history: use git revert.

GitGitHubBeginners