To get started with GitHub, create a free account, install Git, create a repository, clone it, then commit and push your changes with git add, git commit and git push. Authenticate with an SSH key or the GitHub CLI, because GitHub no longer accepts account passwords for Git operations over HTTPS.
This tutorial walks through the full workflow on a small project, including branches and a pull request, and explains the commands you will use every day.
Git is the version control tool that runs on your computer and records the history of your files. GitHub is a hosting service for Git repositories that adds collaboration features such as pull requests, issues and code review. You can use Git without GitHub, but GitHub gives you a remote copy of your project and a place to work with others.
apt, brew or winget.Check the install with git --version.
Since August 2021, GitHub rejects account passwords for Git operations over HTTPS. Use one of these instead:
gh auth login and follow the prompts. It stores credentials securely.Paste the output of cat into GitHub under Settings, SSH and GPG keys. The last command confirms that the connection works.
Click New repository on GitHub, name it my-first-project, choose public or private, and create it. Then clone it, using your own username:
Create a file called index.html:
Stage and commit it, then push:
Refresh the repository page on GitHub and you will see the file and your commit in the history. New repositories on GitHub use main as the default branch name, so older guides that push to master no longer apply.
| Command | What it does |
|---|---|
git status | Shows changed, staged and untracked files |
git add <file> | Stages a file for the next commit |
git commit -m "message" | Records the staged changes |
git push | Uploads commits to the remote |
git pull | Fetches and merges remote changes |
git log --oneline | Shows a compact history |
git diff | Shows unstaged changes |
Write commit messages in the imperative mood, for example "Fix login redirect", and keep each commit focused on one change.
Work on a branch so that main stays stable.
After pushing, GitHub shows a button to open a pull request. A pull request lets teammates review the change, discuss it and run automated checks before it is merged into main. After the merge, update your local copy:
You can also create the pull request from the terminal with gh pr create.
git pull --rebase, resolve any conflicts, then push again.git add and commit.git restore --staged <file> to unstage before committing.Add a .gitignore file early to keep build output, dependencies and local environment files out of the repository.
No. Git works locally without any hosting service, but GitHub adds backup, collaboration and review.
GitHub stopped supporting password authentication for Git over HTTPS in 2021. Use SSH, the GitHub CLI or a personal access token.
New repositories use main. Check your repository's default branch, and in a team, push to a feature branch and open a pull request.
git fetch downloads remote changes without changing your files. git pull fetches and then merges or rebases them into your current branch.
Install Git, authenticate with SSH or the GitHub CLI, then clone, edit, commit and push. Use branches and pull requests for team work, keep main stable, write clear commit messages and ignore files that should not be tracked.