Getting Started with Git and GitHub
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production; see the section bibliography for the reference material consulted while preparing these pages. |
This page is the entry point to the section: what version control is and why Git keeps a full copy of history on
every machine, how Git (the tool) relates to GitHub (a hosting and collaboration platform built around it),
installing Git, the one-time setup every new machine needs, creating a GitHub account and authenticating against
it, and wiring up IntelliJ IDEA and VS Code. The commands and screenshots on this page and the rest of the section
are checked against Git 2.55.x, GitHub CLI 2.101.x, IntelliJ IDEA 2026.2 and the current stable release of VS Code
with the GitHub Pull Requests and Issues extension, against github.com as it behaved in September 2026, and they
assume the modern default branch name main.
Concept: version control, Git and GitHub
A version control system (VCS) records the history of a set of files as a sequence of snapshots, so that any earlier state can be recovered, two states can be compared, and changes made independently by different people can be combined. Git is a distributed version control system (DVCS): unlike older centralized systems, which keep the full history only on one server and give each developer just the files for a single checkout, Git gives every clone the entire history of the project. There is no technical difference between the copy on a developer’s laptop and the copy on a server — both are complete repositories that can exchange history with each other.
That has practical consequences worth internalising before running a single command:
-
Almost every operation — viewing history, creating a branch, committing, comparing two versions — is local and instant, because it never needs the network.
-
Losing the server does not lose history: any clone can restore it, because any clone already has it.
-
"Syncing" is not automatic. Two repositories only exchange history when one explicitly pushes to or pulls from the other; Fetch, Pull and Push covers this in depth.
Git is the command-line tool (and the underlying data model) that implements this. It has no concept of user accounts, issues, pull requests or a web page — it only manages repositories and the history inside them. GitHub is a separate product: a hosting service that stores Git repositories on its servers and layers collaboration features on top — a web UI, access control, issues, pull requests, code review, Actions for CI/CD, and more. GitHub is one of several such platforms (GitLab and Bitbucket are others); everything this section teaches about Git itself applies to any of them, while the "On GitHub.com" parts of each page are specific to GitHub. This distinction is explained in GitHub’s own About Git page.
In everyday use, one Git repository lives on a developer’s machine (the local repository) and a related copy lives
on GitHub (a remote repository, conventionally named origin). They start out identical and then diverge as each
side records its own commits, until an explicit push or pull brings them back in sync:
Repositories and Cloning and Commits explain the working directory, staging area and local repository shown above in detail.
Installing Git
Git 2.55 is available for every major platform. git --version confirms both that Git is installed and which
release it is:
git --version
# git version 2.55.0
macOS — the simplest path is to run a Git command from a terminal; if the Xcode Command Line Tools are not yet installed, macOS offers to install them, which includes Git:
git --version # triggers the Xcode Command Line Tools installer if Git is missing
A more current release than the one Apple ships can be installed with the official macOS installer or a package manager such as Homebrew:
brew install git
Windows — download and run the "Git for Windows" installer, which bundles the git command, Git Bash and Git
Credential Manager:
winget install --id Git.Git -e --source winget
Linux — install from the distribution’s package manager, which is usually close enough to current for everyday use; the project’s own download page links a repository with newer builds when it is not:
sudo apt install git # Debian, Ubuntu
sudo dnf install git-all # Fedora, RHEL, CentOS
Derived from Pro Git, 1.5 Installing Git and Downloads for Git, which link the current installer for every platform.
First-time setup
Git stores configuration in layered files: a system-wide file, a per-user file (--global), and a per-repository
file (--local, the default), with each level overriding the one before it. Two settings are required before
Git will let a commit be made, because every commit records who made it:
git config --global user.name "<your-name>"
git config --global user.email "<your-email>"
Since Git 2.28, the name of the branch an empty repository starts on is also configurable; setting it once avoids
depending on Git’s historical default of master:
git config --global init.defaultBranch main
The editor Git opens for commit messages, merge messages and interactive rebases defaults to the platform’s
$EDITOR or the built-in fallback vi (the Git for Windows installer asks for an editor during installation,
with Vim preselected); pointing it at something more
familiar is a common first tweak:
git config --global core.editor "code --wait" # VS Code; use vim, nano, "idea --wait" or similar as preferred
One more setting worth knowing about at this stage is pull.rebase, which decides whether git pull merges or
rebases the fetched commits onto the local branch — Fetch, Pull and Push explains the two behaviours and
when to prefer each; there is no need to set it yet.
To confirm what is currently configured, and which file each setting came from:
git config --list --show-origin
Derived from Pro Git, 1.6 First-Time Git Setup.
Getting help
Every Git command has a manual page, reachable two equivalent ways, plus a shorter usage summary:
git help config
git config --help # equivalent to git help config
git config -h # a short flag summary instead of the full manual page
git help <command> and git <command> --help open the full manual (the same content as
the online Git reference); git <command> -h prints a terse usage summary in the
terminal without leaving it. Derived from
Pro Git, 1.7 Getting Help.
Creating a GitHub account and authenticating
A GitHub account is created at github.com/signup; the sign-up flow (username, email verification, and enabling two-factor authentication, which GitHub strongly recommends) is covered by GitHub’s own Creating an account on GitHub and is not repeated here.
Once an account exists, Git on the local machine needs a way to prove it is acting as that account whenever it
talks to GitHub over the network (git clone, git push, git fetch/git pull against a private repository).
GitHub supports two transport protocols, each with its own authentication:
| HTTPS | SSH | |
|---|---|---|
URL form |
|
|
Credential |
A short-lived token, stored and refreshed by a credential helper (or GitHub CLI) |
A locally generated key pair; the private key never leaves the machine |
Typical setup |
Install Git Credential Manager (bundled with Git for Windows, installable separately elsewhere), or
|
|
Works through |
Most corporate proxies and firewalls (standard HTTPS traffic) |
Only where outbound SSH (port 22, or GitHub’s HTTPS-tunnelled fallback) is allowed |
HTTPS with a credential helper. Git Credential Manager (GCM) is the credential helper GitHub recommends: the
first git push or git clone against a private repository over HTTPS opens a browser to sign in, and GCM then
stores and refreshes the resulting credential automatically, so it is not asked for again.
HTTPS via GitHub CLI. Alternatively, gh auth login authenticates both the gh command and, when asked, Git
itself for HTTPS operations:
gh auth login
# ? Where do you use GitHub? GitHub.com
# ? What is your preferred protocol for Git operations on this host? HTTPS
# ? Authenticate Git with your GitHub credentials? Yes
# ? How would you like to authenticate GitHub CLI? Login with a web browser
Derived from Set up Git,
Caching
your GitHub credentials in Git and gh auth login.
SSH keys. Generate a modern Ed25519 key pair (RSA is still accepted but no longer recommended for new keys), protecting it with a passphrase:
ssh-keygen -t ed25519 -C "<your-email>"
# Enter a file in which to save the key (press Enter for the default location)
# Enter a passphrase (recommended)
Then add the public key (the .pub file, never the private one) to the account under Settings > SSH and GPG
keys > New SSH key, and confirm the connection:
ssh -T git@github.com
# Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.
Derived from Connecting to GitHub with SSH.
Personal access tokens. Where neither a credential helper nor gh is available — some CI runners, some scripted
environments — a personal access token can be used as the HTTPS password directly (git clone
https://<your-username>@github.com/<owner>/<repo>.git, entering <TOKEN> when prompted for the password, or
stored in a credential helper). Treat a token exactly like a password: never commit it, and scope and expire it as
narrowly as the task allows. This is documented as the fallback, not the default, path in
Set up Git.
IDE setup
IntelliJ IDEA
IntelliJ IDEA bundles Git support and only needs to know where the git executable is:
-
Open Settings > Version Control > Git (IntelliJ IDEA > Settings on macOS).
-
IntelliJ IDEA auto-detects an installed Git executable; if it cannot find one, browse to it manually in the "Path to Git executable" field, then use "Test" to confirm the IDE can run it.
Derived from Set up a Git repository.
A GitHub account is added separately, so the IDE can clone private repositories and drive pull requests:
-
Open Settings > Version Control > GitHub.
-
Click + to add an account, then either log in through a browser or paste a personal access token.
Derived from Using GitHub integration in IntelliJ IDEA.
VS Code
VS Code has Git support built in and needs no extension for local commits, branching or viewing history through the
Source Control view (also reachable with Ctrl+Shift+G, ⌃⇧G on macOS); it only needs Git
itself to already be installed and on the PATH. Cloning a private repository or pushing to GitHub prompts a
browser sign-in the first time. Derived from
Source Control overview.
Reviewing and creating pull requests and issues from inside the editor needs the GitHub Pull Requests and Issues extension:
-
Install the extension from the Extensions view (search for "GitHub Pull Requests and Issues", published by GitHub) or the Marketplace page.
-
Sign in with GitHub from the GitHub icon added to the Activity Bar.
Derived from Working with GitHub in VS Code.
Common mistakes and tips
| Mistake | Why it bites, and what to do instead |
|---|---|
Setting |
Commits are attributed by this email; GitHub only links a commit to a profile when the email matches one on the
account (or its no-reply address). Use the same email registered on GitHub, or its |
Skipping |
Git still defaults a brand-new repository’s first branch to |
Pasting a real token into a command or file |
Anything typed on the command line can end up in shell history, and anything committed stays in history even after being removed later. Always use a credential helper or an environment variable, never a literal token in a script or commit. |
Assuming |
It opens the manual page installed locally ( |