If you're new to the programming world, one of the first things you need to master is Git and GitHub. Git is a version control system that lets you track every code change, collaborate with a team, and go back to a previous version if a mistake happens. GitHub is a cloud-based hosting platform for storing Git repositories online. The combination of the two is the industry standard for almost every professional developer.
What Is Git and Why Is It Important?
Imagine you're working on a project and accidentally delete important code. Without Git, you'd have to recall it all from scratch. With Git, you just go back to a previous commit. Git also makes collaboration easy — many developers can work on the same project without overwriting each other's work.
Installing Git
Download Git from the official site https://git-scm.com and follow the installation process for your operating system. After installing, verify it with the following command in the terminal:
git --version
Next, set your identity so each commit is recorded under your name:
git config --global user.name "Your Name"
git config --global user.email "email@you.com"
Creating Your First Git Repository
Go into your project folder, then initialize a Git repository:
cd /path/to/project-folder
git init
This command creates a hidden .git folder that stores your project's entire change history.
The Basic Git Workflow
There are three main stages in Git you need to understand:
- Working Directory — where you edit files directly.
- Staging Area — the preparation area before committing.
- Repository — the permanent storage of all commit history.
After editing a file, add it to the staging area then create a commit:
git add file-name.html
git add .
git commit -m "Add the home page"
Connecting to GitHub
Create an account at https://github.com, then create a new repository (click the New button). After the repository is created, connect your local repository to GitHub:
git remote add origin https://github.com/username/repo-name.git
git branch -M main
git push -u origin main
The push command sends your local code to GitHub. The -u flag sets the upstream so that from then on you just type git push.
Pulling Changes from GitHub
If your teammate has made changes on GitHub, you can download them locally with:
git pull origin main
Or if you want to copy someone else's repository to your local machine:
git clone https://github.com/username/repo-name.git
Viewing Status and Commit History
Two commands you'll often use are:
git status
git log --oneline
git status shows which files have changed or aren't committed yet. git log --oneline shows a concise list of commits along with their unique hashes.
Tips for Beginners
- Always run
git statusbefore committing to make sure the correct files are staged. - Write clear and descriptive commit messages, for example "Add login form validation" not just "update".
- Don't commit sensitive files like
.envthat contain passwords. Use a.gitignorefile to exclude them. - Commit often with small changes rather than one big commit that's hard to track.
Creating a .gitignore File
The .gitignore file tells Git which files or folders don't need to be tracked. Create this file in the project root:
.env
node_modules/
vendor/
*.log
With this, the node_modules folder or .env file won't be pushed to GitHub.
Conclusion
Git and GitHub are an important foundation in the modern software development world. By understanding the basic flow — init, add, commit, push, and pull — you're ready to collaborate on real projects. Start with a simple project, get used to the basic commands, and over time using them will feel natural. The more you use them, the more you'll appreciate how important version control is for maintaining code quality and safety.