Git and GitHub are related, but they are not the same thing. Git tracks versions of your project. GitHub can host a Git repository remotely and provide tools for collaboration, review, and project management.
What Is the Difference Between Git and GitHub?
This distinction is one of the first things to understand when learning version control.
Git
Git is a distributed version control system. It records changes to files and allows you to work with different versions of a project.
GitHub
GitHub is a platform that can host Git repositories online and provide collaboration features around them.
You can use Git without GitHub. You can create commits, branches, and version history entirely on your own computer.
GitHub becomes useful when you want a remote copy of the repository or need features such as pull requests, issue tracking, code review, and collaboration.
A useful way to remember the distinction is: Git manages the version history; GitHub can host and help people collaborate around that Git repository.
What Is a Repository?
A repository, often shortened to repo, is the project being tracked by Git along with its version history and related Git information.
If you already have a project folder and want Git to start tracking it, you can initialize a repository.
Initialize Git
git initThis initializes a Git repository in the current directory.
Before running the command, make sure your terminal is in the correct project folder. Accidentally initializing Git in the wrong directory can create confusion about which files belong to the repository.
Understand the Basic Git Workflow
At a beginner level, it helps to think about your files moving through a few stages.
You create or edit files in your working directory.
You choose which changes should be staged.
You commit the staged changes to the repository history.
When using a remote repository, you can push your commits to it.
This means saving a file in your code editor is not the same as creating a Git commit, and creating a local commit is not the same as uploading that commit to GitHub.
Check What Has Changed With git status
One of the most useful Git commands for beginners is:
Check Repository Status
git statusThis command helps you see information such as which files have changed, which files are untracked, and which changes are staged for the next commit.
When you are unsure about the current state of your repository, git status is often a useful place to start.
Stage the Changes You Want to Commit
Git allows you to choose which changes should be included in the next commit.
To stage a particular file:
Stage One File
git add page.tsxTo stage changes under the current directory:
Stage Changes
git add .git add . can stage multiple changed and untracked files. Check the repository status so you do not accidentally include files that should remain outside the commit.
Create a Commit
A commit records a snapshot of the staged changes in the repository history.
Create a Commit
git commit -m "Add contact page"The message should briefly describe the purpose of the change. Compare these two messages:
Less Helpful
Update files
More Helpful
Add contact form validation
Clear commit messages make the project history easier to understand later.
It is also usually easier to understand a history made of focused commits than one enormous commit containing several unrelated changes.
How Does a Local Repository Connect to GitHub?
A repository on your computer is local. A repository hosted elsewhere, such as on GitHub, can be configured as a remote.
A common remote name is origin.
Add a Remote
git remote add origin <repository-url>Replace <repository-url> with the appropriate remote repository URL.
You can inspect configured remotes with:
View Remotes
git remote -vAuthentication may be handled differently depending on whether you use HTTPS, SSH, a credential manager, or a development environment with GitHub integration.
Understand Clone, Pull, and Push
These commands are commonly used when working with remote Git repositories.
| Command | Main Purpose |
|---|---|
| git clone | Create a local copy of an existing repository |
| git pull | Fetch remote changes and integrate them into the current branch |
| git push | Send local commits to a configured remote repository |
Clone a Repository
git clone <repository-url>Pull Remote Changes
git pullPush Local Commits
git pushGit commands depend on the repository's current branch, remote configuration, and upstream tracking. If a command does not behave as expected, check the repository state rather than repeatedly rerunning it.
What Is a Git Branch?
Branches allow development to proceed along separate lines without immediately changing another branch.
For example, you might create a branch for a new contact page while keeping the main branch unchanged until the work is ready.
Create and Switch to a Branch
git switch -c contact-pageTo see your local branches:
List Branches
git branchTo switch to an existing branch:
Switch Branch
git switch mainOlder tutorials may use git checkout for some branch operations. You may therefore encounter both commands while working with existing projects or documentation.
What Is a Pull Request?
A pull request is a GitHub collaboration feature used to propose changes from one branch for review and possible integration into another branch.
A common workflow might look like this:
Create a branch for the change.
Edit the project and test the work.
Stage and commit the changes.
Push the branch to GitHub.
Open a pull request.
Review the differences and any automated checks.
Resolve issues if necessary and merge when the change is ready.
Pull requests are particularly useful for team projects because they create a clear place to discuss and review proposed changes before integration.
Common Git & GitHub Mistakes
1. Assuming saving a file creates a commit
Saving updates the file on your computer. Git does not create a new commit until you stage the intended changes and commit them.
2. Assuming a commit automatically appears on GitHub
A local commit remains in your local repository until it is pushed to the appropriate remote branch.
3. Running commands without checking the current branch
Before committing, pulling, merging, or pushing, make sure you understand which branch you are currently working on.
4. Committing secrets
Passwords, private keys, API credentials, access tokens, and sensitive configuration should not be committed to a repository.
If a credential has already been committed, it may still exist in repository history. Treat an exposed credential as compromised, rotate or revoke it where appropriate, and then address the repository history separately.
5. Committing unnecessary generated files
Dependencies, build output, temporary files, environment files, and editor-specific files may not belong in version control. A .gitignore file can tell Git which matching untracked files should normally be ignored.
6. Using unclear commit messages
Messages such as “stuff,” “changes,” or “final final” make the project history harder to understand. Describe the purpose of the change.
7. Using destructive commands without understanding them
Some Git operations can discard local changes or rewrite history. Do not copy a reset, clean, rebase, or force-push command simply because it appears in a troubleshooting answer. Understand its effect first.
Beginner Git Command Checklist
You do not need to memorize every Git command immediately. Start by understanding what these common commands do:
| Command | Purpose |
|---|---|
| git init | Initialize a repository |
| git clone | Copy an existing repository locally |
| git status | Inspect the current repository state |
| git add | Stage changes for a commit |
| git commit | Record staged changes in repository history |
| git branch | Inspect or manage branches |
| git switch | Switch branches or create and switch to one |
| git pull | Fetch and integrate remote changes |
| git push | Send local commits to a remote |
More important than memorizing commands is understanding the state of the repository before you run them.
Which repository am I working in?
Which branch am I currently on?
Which files have changed?
Which changes are staged?
Which changes have been committed?
Is a remote repository configured?
Have my local commits been pushed?
Stuck With a Repository or Project Workflow?
Share the Git command, error message, repository state, and what you were trying to accomplish. The issue can then be worked through in the context of your actual project.
