What Is Git and GitHub? A Beginner's Guide
If you are learning programming or software development, you may have heard of Git and GitHub. These tools help developers manage project changes, organize code and collaborate with other people.
In this beginner-friendly guide, you will learn the difference between Git and GitHub, understand common terms and practice basic Git commands.
Git is a version control system that records changes to files.
GitHub is an online platform for hosting Git repositories and collaborating on software projects.
What Is Git?
Git is a distributed version control system. It records changes to files and helps you understand how a project has developed over time.
Imagine you are building an Android app. You change the home screen, add a new feature and later discover that a change has caused a problem. Git can help you inspect the history, compare versions and recover earlier work when needed.
Git is commonly used for software projects, but it can also track changes to other types of text-based files and project documents.
What Is Version Control?
Version control is a method of tracking changes to files over time. It helps you keep a record of your work instead of creating many confusing copies such as:
- project-final
- project-final-new
- project-final-new-2
- project-final-working
With Git, you can save checkpoints, compare changes and create separate branches for different tasks.
What Is GitHub?
GitHub is an online development platform built around Git repositories. Developers use it to host projects, share code, review proposed changes, track issues and document their work.
A Git repository can exist on your device without GitHub. GitHub is useful when you want to store a remote copy, share your project or work with others.
GitHub also provides features such as pull requests, issue tracking and project collaboration tools.
Git vs GitHub
| Git | GitHub |
|---|---|
| A version control system | An online platform for software development and collaboration |
| Tracks file changes and project history | Hosts repositories and adds collaboration features |
| Can be used locally without an internet connection | Online features generally require an internet connection |
| Commonly used through a terminal or compatible application | Offers a website, collaboration tools and integrations |
What Is a Repository?
A repository, often called a repo, is a project location managed by Git. It contains project files and the information Git uses to record their history.
A repository may contain source code, documentation, images, configuration files and other resources. Git repositories can exist locally on your device or be hosted remotely on a service such as GitHub.
What Is a Commit?
A commit records a set of staged changes in the repository history. A commit usually includes a message explaining what was changed.
git commit -m "Add homepage"
A clear message makes it easier to understand the purpose of a change later. A commit records the staged snapshot; it does not automatically upload your work to GitHub.
What Is a Branch?
A branch is a separate line of development. It lets you work on a feature or fix without immediately changing the branch used for the main version of the project.
main
feature-login
feature-dark-mode
bug-fix
These are example branch names, not commands. You can create a branch with:
git switch -c feature-login
The command creates and switches to a new branch named
feature-login.
What Is the Main Branch?
Many projects use main as the name of their primary branch.
Older or differently configured projects may use another name, such as
master. The branch name depends on the project's conventions.
Common Git Commands
Git commands are often entered in a terminal or command-line interface. Below are some commands beginners commonly use.
1. Check the Git Version
git --version
Displays the installed Git version, if Git is available in your environment.
2. Create a Repository
git init
Initializes a Git repository in the current directory.
3. Check Repository Status
git status
Shows the current branch and information about changed, staged and untracked files.
4. Stage a File
git add index.html
Stages changes to index.html for the next commit.
5. Stage Changes in the Current Directory
git add .
Stages eligible changes under the current directory. Check the status first to ensure you are not staging files you did not intend to include.
6. Create a Commit
git commit -m "Add homepage"
Records the staged changes in the local repository history.
7. View Commit History
git log
Displays commit history. Press q in many terminal pagers to exit the log view.
8. See What Has Changed
git diff
Shows unstaged differences in tracked files. To inspect staged changes, use:
git diff --staged
What Does Git Clone Do?
The git clone command creates a local copy of an existing
repository, including its Git history and relevant remote configuration.
git clone https://github.com/OWNER/REPOSITORY.git
Replace OWNER and REPOSITORY with the actual owner
and repository name. The repository must be accessible to you.
What Is a Remote Repository?
A remote repository is a repository stored somewhere other than your local working copy. A remote is a named reference to a repository that Git can communicate with.
The common default remote name is origin, although names can vary.
To list configured remotes, run:
git remote -v
What Is Push?
A push sends local commits to a remote repository, provided you have permission and the remote is configured correctly.
git push -u origin main
This example pushes the local main branch to the remote named
origin and sets an upstream tracking relationship. It assumes
that the remote exists and your local branch is named main.
What Is Pull?
A pull fetches changes from a remote repository and integrates them into your current local branch. Depending on your Git configuration, the integration may use a merge or rebase.
git pull
Before pulling, check your working tree and understand how your project handles local changes and remote updates.
Why Do Developers Use Git?
- Track changes to project files.
- Review project history.
- Experiment with features using branches.
- Compare different versions of code.
- Coordinate work with other developers.
- Investigate problems and recover earlier work.
- Manage changes in large or long-running projects.
Why Do Developers Use GitHub?
- Host Git repositories online.
- Share projects with other people.
- Review code and discuss proposed changes.
- Track bugs, tasks and feature requests.
- Maintain project documentation.
- Collaborate on open-source projects.
What Is a Pull Request?
A pull request, often called a PR, is a proposal to merge changes from one branch into another. It gives collaborators a place to review the changes, discuss them and request improvements before merging.
For example, you might create a branch for a login feature, commit your work and open a pull request asking the project team to review it.
What Is an Issue?
An issue is a record of a problem, task, question or feature request. GitHub issues can help teams organize work and keep discussions connected to a project.
What Is Code Review?
Code review is the process of examining proposed changes before they are accepted into a project. Reviewers may identify bugs, suggest improvements and check whether the changes follow project standards.
Public vs Private Repositories
| Public Repository | Private Repository |
|---|---|
| Generally visible to anyone | Access is limited to authorized people |
| Often used for open-source projects and public portfolios | Useful for projects that require restricted access |
| People may discover and inspect the published code | Access depends on permissions and platform settings |
Repository visibility does not replace good security practices. Never commit passwords, private keys or secret API credentials, even to a private repository. Access can change, and secrets can be exposed through mistakes or compromised accounts.
What Is Open-Source Software?
Open-source software is software distributed under a license that grants specific rights to use, inspect, modify and redistribute its source code. The exact rights and obligations depend on the license.
GitHub hosts many open-source projects. Depending on the project's rules, developers may study the code, report problems, suggest improvements or submit contributions.
GitHub and Other Git Hosting Platforms
GitHub is not the only service that hosts Git repositories. Other services also support Git hosting and collaboration. The basic Git concepts—commits, branches, merges and repository history—apply across these services.
Is GitHub Free?
GitHub offers a free plan with many repository and collaboration features. Other features, usage limits and services may depend on the plan or current terms. Check the official GitHub website for up-to-date details.
A Simple Beginner Git Workflow
A common workflow for a new local project is:
- Create or open your project folder.
- Initialize Git if the folder is not already a repository.
- Make changes to project files.
- Check the changes with
git statusandgit diff. - Stage the changes you want to save.
- Commit the staged changes with a useful message.
- Configure a remote repository if you want to share the project online.
- Push your commits when the branch and remote are configured.
Example: Save Your First Commit
In a new project folder, you can start with these commands:
git init
git status
git add .
git status
git commit -m "Initial commit"
git log
This example creates a repository, checks its status, stages files, records a commit and displays the history. It assumes that Git is installed and that the folder contains files you intend to track.
Connecting a Project to GitHub
To push a local project to GitHub, first create a repository on GitHub and
follow the instructions provided for connecting an existing local repository.
For a remote named origin and a local branch named
main, the commands may look like this:
git remote add origin https://github.com/OWNER/REPOSITORY.git
git branch -M main
git push -u origin main
Replace the example URL with your actual repository URL. If your project already has a remote or contains commits from GitHub, the correct steps may differ. Follow the repository's instructions and resolve any errors before retrying.
Can Beginners Learn Git on a Phone?
Yes. Some mobile applications and online development environments support Git operations. Available features depend on the application, and using a terminal may be easier on a computer. You can still learn the main concepts and practice with a small project using a suitable mobile tool.
Git Security and API Keys
Developers often work with APIs, databases and online services. Some of these services use API keys, access tokens or other credentials to control access. Treat secret credentials as sensitive information.
For browser-based applications, remember that code delivered to a visitor's browser can be inspected. Do not put a server secret into HTML or JavaScript that is sent to the public. Requests requiring private credentials should normally be handled by a suitably secured backend.
If a secret is accidentally published, deleting the visible line may not be enough because the secret can remain in repository history or copies. Revoke or rotate the exposed credential promptly and follow the provider's security guidance.
Common Beginner Mistakes
- Using commands without understanding their purpose.
- Writing vague commit messages such as "changes".
- Forgetting to check the repository status.
- Staging files that should not be included in a commit.
- Assuming a commit automatically uploads files to GitHub.
- Sharing sensitive information in a repository.
- Ignoring the project's README and contribution instructions.
- Trying to push before configuring the remote or checking permissions.
git status regularly. It helps
you understand which branch you are on and which changes are staged,
unstaged or untracked.
Frequently Asked Questions
Is Git the same as GitHub?
No. Git is a version control system, while GitHub is an online platform that hosts Git repositories and provides collaboration features.
Do I need GitHub to use Git?
No. You can use Git locally without creating a GitHub account. GitHub is useful when you want online hosting, sharing or collaboration.
Is Git only for programmers?
Git is mainly associated with software development, but version control can also be useful for tracking changes to other files and text-based projects.
Does git commit upload my files to GitHub?
No. A commit records staged changes in your local repository. You generally need to push commits to a configured remote repository to upload them.
What is the difference between git fetch and git pull?
git fetch downloads remote updates without automatically
integrating them into your current branch. git pull fetches
updates and then integrates them, usually through a merge or rebase.
What should I learn first?
Start with repositories, git status, git add,
git commit, git log and branches. Then learn how
remotes, push, pull, merging and pull requests work.
Is GitHub useful for building a programming portfolio?
Yes. You can publish suitable projects, explain how they work in a README file and show how your work develops over time. Only publish material you have the right to share, and remove all secret credentials.
Official Learning Resources
Use these official resources to continue learning. Documentation may be updated as the tools evolve.
- Git Official Documentation — reference guides and documentation for Git.
- Pro Git Book — a detailed book about Git concepts and workflows.
- GitHub Getting Started Guide — introductory guidance for using GitHub.
- GitHub Hello World Tutorial — a beginner exercise using repositories, branches and pull requests.
Conclusion
Git helps developers track changes, maintain project history and manage different lines of development. GitHub provides online repository hosting and tools for sharing and collaborating on projects.
Learning both tools is a valuable step toward modern software development. Start with a small project, practice the basic commands and build your skills gradually.