Getting Started with Git: From Your First File to GitHub

Git helps you track changes, keep a project’s history and collaborate without relying on folders named “final,” “final-new” and “actually-final.”

This guide introduces the basic workflow and walks you through your first commit and upload to GitHub.

Git and GitHub are different

Git is a version control system that runs on your computer. GitHub hosts Git repositories online and adds collaboration features such as pull requests.

You can use Git locally without a GitHub account or an internet connection.

Understand the three main areas

  • Working directory: The files you create and edit.
  • Staging area: The changes selected for your next commit.
  • Local repository: The recorded history of your project.

The everyday workflow is: edit, review, stage and commit. Pushing shares your local commits with a remote repository.

1. Install and configure Git

Follow the official installation instructions, then check:

git --version

Set the identity attached to your commits, replacing these examples with your details:

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

The --global setting applies across your repositories unless overridden. Your commit email can be visible when you share the history, so choose an address you are comfortable publishing.

2. Create a practice repository

In your terminal, create and enter a new folder:

mkdir git-practice
cd git-practice
git init
git branch -m main

This initialises Git and names the initial branch main.

Using your editor, create a file named README.md inside the folder. Add:

# Git Practice

A small repository for learning Git.

3. Review and stage the file

git status
git add README.md
git diff --cached

git status shows the file’s tracking state. git add stages its current contents, and git diff --cached shows what you are about to commit.

If you edit the file again after staging it, stage those additional edits if you want them included too.

4. Make your first commit

git commit -m "Add project introduction"
git log --oneline

A commit records the staged snapshot in your local history. Use a concise message describing the change. There is no universal requirement that every message must be under 50 characters.

git log --oneline should now show your commit with its abbreviated identifier.

5. Connect to GitHub

Create an empty repository on GitHub. For this walkthrough, do not initialise it with a README, licence or gitignore file, because your local repository already has its own first commit.

Copy the repository’s HTTPS URL and substitute it below:

git remote add origin https://github.com/YOUR-USERNAME/git-practice.git
git remote -v
git push -u origin main

Complete authentication using a supported GitHub method. Your Git commit identity does not sign you in to GitHub.

origin is the remote’s local name. The -u option sets the upstream relationship for your branch.

Refresh the GitHub repository page. Your README and first commit should appear.

Practise one more change

Add a sentence to the README, then review it:

git diff
git add README.md
git diff --cached
git commit -m "Expand project description"
git push

By default, git diff compares unstaged tracked changes against the staging area. It does not display the contents of untracked files.

You now have the core workflow: make a focused change, inspect it, record it locally and share it when ready.

Further reading: The official Pro Git book.

No comments