Git for Beginners: A Step-by-Step Guide
Master the absolute basics of Git: cloning, branching, and pushing code safely. Essential for every developer.

Git for Beginners: A Step-by-Step Guide
Introduction
Git is the industry standard for version control. Whether you're a solo developer or part of a huge team, mastering Git is essential. This guide covers the absolute basics to get you started.
What is Git?
Git is a distributed version control system that tracks changes in your source code during software development. It allows you to:
- Revert files to previous states.
- Track who made changes and why.
- Work on parallel branches without affecting the main code.
How to Clone from GitHub?
Cloning creates a local copy of a repository from a remote source like GitHub.
- Go to the repository page on GitHub.
- Click the green Code button and copy the URL (HTTPS or SSH).
- Open your terminal and run:
Example:git clone <repository-url>git clone https://github.com/username/project-name.git
How to Create a Branch?
Branches let you work on new features or fixes in isolation. To create and switch to a new branch:
git checkout -b feature/my-new-feature
Tip: Use descriptive names like bugfix/login-error or feature/user-profile.
How to Push to a Branch
Once you've made commits, you need to send them to the remote repository.
git push -u origin feature/my-new-feature
The -u flag sets the "upstream" link, so you can just run git push next time.
How to Pull from a Branch
Pulling from your own branch: To update your local branch with changes from the remote:
git pull origin feature/your-branch-name
Pulling from another branch (e.g., master/main): To get the latest updates from the main codebase into your branch:
git checkout feature/your-branch-name
git pull origin main
The Golden Rule: Never Push to Master
Directly pushing to master (or main) is risky. It can bypass code reviews and break the production application. Always:
- Create a branch.
- Make changes.
- Push the branch.
- Create a Pull Request (PR).
How to Raise a PR
A Pull Request notifies teammates that you have changes ready to be merged.
- Push your branch to GitHub.
- Go to the repository on GitHub.
- You'll often see a "Compare & pull request" button. Click it.
- Add a title and description.
- Click Create Pull Request.