Git is an awesome tool that developers everywhere use to keep track of their code. In this article, we’ll walk you through everything - from setting it up to making your first commit-breaking it down step-by-step with handy tips for beginners.
Git is a distributed version control system cooked up by Linus Torvalds back in 2005. It lets you track changes in your code, save its history, and jump back to earlier versions if you need to. It’s fast, flexible, and super reliable, which is why it’s the go-to tool for developers.
Git shines when you’re working with others. It lets multiple people hack away at a project at the same time, sync up their changes, and avoid stepping on each other’s toes. With branches, everyone can work on their own piece of the puzzle and then merge it into the main codebase later.
Even if you’re flying solo, Git’s got your back:
Start using Git with your very first project—it’ll build a solid habit and make life easier down the road.
Git works on pretty much anything: Linux, macOS, Windows—you name it. You can grab it from the official site (git-scm.com) or use your system’s package manager.
sudo apt update
sudo apt install git
sudo dnf install git
brew install git
Check it worked with:git --version
Head to git-scm.com and download the installer. Run it and follow the steps:
git --version
Before you commit anything, tell Git who you are: git config --global user.name "Your Name"
git config --global user.email "you@example.com"
The --global flag sets this for all your projects. Peek at your settings with: git config --list
If you try to commit without setting these up, Git will throw a fit:*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
It won’t let you commit until you sort this out.
Git itself doesn’t need a login, but to work with remote repos (like GitHub, GitLab, or Bitbucket), you’ll need to sign in:
Via HTTPS: Use your username and a token (Personal Access Token): git remote add origin https://github.com/username/repository.git
It’ll ask for your token the first time you push.
Via SSH: Set up an SSH key:
ssh-keygen -t rsa -b 4096 -C "your@email.com"
git remote add origin git@github.com:username/repository.git
cd path/to/folder
git init
GitHub/GitLab: Copy the repo URL (HTTPS or SSH) and run:git clone https://github.com/username/repository.git
This pulls the code down and connects it to the remote repo.
Make a new branch for your changes:git checkout -b feature/branch-name
.
Switch to your new branch branch:git checkout branch-name
.
Keep your local copy fresh:git pull origin main
git add .
git commit -m "what you changed"
Send your changes to the remote repo:git push origin feature/branch-name
If someone else updated the remote branch and you didn’t pull those changes before committing, git push will fail. Here’s how to undo your last commit without losing your work, sync up, and push your changes without a hitch:git reset --soft HEAD^
HEAD^ points to your last commit. --soft undoes the commit but keeps your changes staged and ready to go.
If your files are staged but you want them back in your working area:git restore --staged .
After undoing the commit, here’s how to get the latest code and push your work:
git pull origin main
git add .
git commit
You can chain commands with && to save time. These combos are perfect for repetitive tasks and work great with Commands Manager - a tool that lets you store, search, and run commands with shortcuts, plus sync them across devices.
git add . && git commit -m "Quick update" && git push
git pull origin main && git add . && git commit -m "Sync and update"
git checkout -b feature/new-task && git push --set-upstream origin feature/new-task
git add README.md && git commit -m "Update README" && git push
git pull --rebase origin main && git add . && git commit -m "Rebase and commit"
With Commands Manager:
Cloud sync keeps your commands handy wherever you work.
Git’s more than just a tool - it’s a way to keep your code in check. We’ve covered installing it, setting it up, starting a project, and making your first commit. With the basics down and tricks like Commands Manager in your pocket, you’ll be coding smarter solo or with a team. Keep practicing, and Git will feel like second nature!