Git is a free tool that keeps the history of your project. Every time you save a change with Git, it records a snapshot of your files. You can then see what changed, go back to an older version, and work on the same project with other people without overwriting each other's work.
This guide takes you from zero to your first push on GitHub: install Git, create a repository, add, commit and push, then keep a short command table for daily use.
What is Git in simple words
Think about how you saved your final-year project report: report.docx, report-final.docx, report-final-2.docx, report-really-final.docx. You kept copies so you could go back. But you could not easily see what changed between them, and sharing them with your team was messy.
Git solves this properly:
- You save snapshots called commits, each with a short message such as "Add login page".
- Git remembers who changed what and when.
- You can compare any two versions line by line.
- You can go back to any earlier commit.
- Many people can work on the same files and Git helps join their work.
Git was created by Linus Torvalds in 2005 to manage the Linux kernel source code. Today it is the standard version control tool in software teams.
Git vs GitHub
| Git | GitHub | |
|---|---|---|
| What it is | A tool on your computer | A website that hosts Git repositories |
| Works offline | Yes | No, it is online |
| Main job | Track changes and history | Store, share and review code with others |
| Cost | Free, open source | Free plan plus paid plans |
| Alternatives | Mercurial, SVN (older style) | GitLab, Bitbucket |
You can use Git without GitHub. But to share code or show projects to recruiters, you push your Git repository to GitHub. See Git vs GitHub for more detail.
Three words to learn first
| Word | Meaning |
|---|---|
| Repository (repo) | A project folder that Git tracks. It has a hidden .git folder holding the history. |
| Commit | A saved snapshot of your files with a message. |
| Staging area | A waiting list of changes that will go into the next commit. |
Your files move through three places:
Working folder --git add--> Staging area --git commit--> Repository (history)
(you edit) (ready to save) (saved snapshots)
The staging area lets you choose exactly what goes into a commit. If you changed five files but only two belong to one fix, you add just those two.
Step 1: Install Git
| System | How to install |
|---|---|
| Windows | Download "Git for Windows" from git-scm.com and run the installer. The default options are fine for beginners. |
| macOS | Run git --version in Terminal. If Git is missing, macOS offers to install the Command Line Developer Tools. You can also use Homebrew: brew install git. |
| Ubuntu or Debian Linux | sudo apt update then sudo apt install git |
Check that it worked:
git --version
You should see a line such as git version 2.x.x. Any recent version works for this guide.
Step 2: Tell Git who you are
Git puts your name and email on every commit. Set them once:
git config --global user.name "Ravi Kumar"
git config --global user.email "ravi@example.com"
Use the same email you will use for your GitHub account, so your commits link to your profile. Check your settings with git config --list.
Step 3: Create your first repository
mkdir my-first-repo
cd my-first-repo
git init
Output:
Initialized empty Git repository in .../my-first-repo/.git/
git init creates the hidden .git folder. That folder is the repository's memory. Do not edit or delete it.
Pro tip: Depending on your Git settings, the first branch is called
masterormain. GitHub usesmainfor new repositories. You can rename yours withgit branch -M main, or create the repo withgit init -b main(Git 2.28 or later).
Step 4: Check the status
Create a file called README.md with one line, # My First Repo, then run:
git status
Output:
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
"Untracked" means Git sees the file but is not tracking it yet. Run git status often. It always tells you where you are and suggests the next command.
Step 5: Add and commit
git add README.md
git commit -m "Add README"
Output:
[main (root-commit) 0881de2] Add README
1 file changed, 1 insertion(+)
create mode 100644 README.md
The code 0881de2 is the short form of the commit's ID (a hash). Yours will be different. View the history with:
git log --oneline
0881de2 Add README
To add every changed file at once, use git add . (the dot means "this folder"). Check git status first so you do not add files you did not mean to.
Step 6: Push to GitHub
- Sign in to GitHub and click New repository.
- Give it the name
my-first-repo. Leave "Add a README" unticked, because you already have one. - Click Create repository. GitHub shows you a URL such as
https://github.com/your-username/my-first-repo.git.
Back in your terminal:
git branch -M main
git remote add origin https://github.com/your-username/my-first-repo.git
git push -u origin main
| Command | What it does |
|---|---|
git branch -M main |
Names your branch main |
git remote add origin <url> |
Saves the GitHub address under the short name origin |
git push -u origin main |
Uploads your commits and links your main to GitHub's main |
After the first time, git push alone is enough.
GitHub does not accept your account password for Git commands over HTTPS. On Windows, Git for Windows includes Git Credential Manager, which opens a browser window to sign in. Otherwise, use a personal access token in place of the password, or set up SSH keys.
Refresh the GitHub page. Your README is now online.
The daily Git workflow
Once the repo is set up, your day looks like this:
git pull # get the latest changes from GitHub
# ... edit your files ...
git status # see what changed
git add . # stage the changes
git commit -m "Add search box to home page"
git push # upload to GitHub
Git commands for beginners: short table
| Command | What it does |
|---|---|
git --version |
Shows the installed Git version |
git config --global user.name "Name" |
Sets your name for commits |
git init |
Starts a new repository in this folder |
git clone <url> |
Copies an existing repository to your computer |
git status |
Shows changed, staged and untracked files |
git add <file> |
Stages one file |
git add . |
Stages all changes in this folder |
git commit -m "message" |
Saves staged changes as a commit |
git log --oneline |
Shows the commit history, one line each |
git diff |
Shows changes not yet staged |
git push |
Uploads commits to the remote |
git pull |
Downloads and merges new commits from the remote |
git branch |
Lists branches |
git switch -c <name> |
Creates a new branch and moves to it |
git restore <file> |
Throws away unstaged changes in a file |
For branching, merging, undoing commits and more, see our full Git commands list.
Branches in one minute
A branch is a separate line of work. You make a branch, try a new feature there and merge it back when it works. The main branch stays safe meanwhile.
git switch -c login-page # new branch
# ... work and commit ...
git switch main # back to main
git merge login-page # bring the work in
git switch was added in Git 2.23. Older tutorials use git checkout -b login-page, which does the same.
Common beginner mistakes
| Mistake | Fix |
|---|---|
| Running Git commands outside the project folder | cd into the folder first. The error is "not a git repository". |
Committing passwords or .env files |
Add them to a .gitignore file before the first commit |
Committing node_modules or build folders |
List them in .gitignore |
| Messages like "update" or "changes" | Say what changed: "Fix total price rounding" |
Running git init inside a folder that is already a repo |
You get nested repos. Run it once, in the project's top folder. |
| Forgetting to pull before starting work | Run git pull first to avoid conflicts |
Common mistake: Trying to push before making any commit. Git reports an error like
src refspec main does not match any. Make a commit first, then push.
A simple .gitignore for a Node.js project:
node_modules/
.env
dist/
Next steps
- Push one of your college projects to GitHub with a clear README.
- Make a branch, change something, and merge it back.
- Learn
git log,git diffand safe undo commands from the Git commands guide. - Get comfortable with the terminal using our Linux commands guide.
Recruiters often check a fresher's GitHub profile. Our GitHub for freshers guide shows how to set up a profile that looks professional. When you can explain staging, commits and push without notes, try the Git interview questions.
Frequently Asked Questions
What is Git in simple words?
Is Git the same as GitHub?
What is the difference between git add and git commit?
Is Git free?
Do I need the command line to use Git?
Want to Build Your Career in Java Full Stack with AI?
Join CodeBegun and train with working industry engineers — Discover CodeBegun's Java Full Stack track

