Harry Yates

I'm a web developer focused on TypeScript, React, and Three.js.

Don’t Be a Terminal Git: Essential Git Commands

Thu, 18th Jul 2024

If you’re a developer, mastering Git is a must. It’s the backbone of version control, enabling you to track changes, collaborate seamlessly, and roll back mistakes.

Post

1. Initialising a Repository

Command: git init

What It Does: Creates a new Git repository in your project’s directory. Think of it as starting a scrapbook where all your coding history will be documented.

2. Checking the Status

Command: git status

What It Does: Tells you the status of your files in the working directory and staging area. Are they tracked? Untracked? Modified? This command gives you the lowdown.

3. Adding Changes

Command: git add

What It Does: Stages your changes, getting them ready to be committed. It’s like tagging photos in your scrapbook that you want to glue down.

4. Committing Changes

Command: git commit -m "Your message"

What It Does: Records your changes in the repository with a message. Consider it as writing a caption for a page in your scrapbook.

5. Viewing the Log

Command: git log

What It Does: Shows the commit history of your project. Each entry is like a page in your scrapbook with detailed captions.

6. Branching Out

Command: git branch

What It Does: Lists, creates, or deletes branches. Branches are like parallel universes where you can make changes without affecting the main storyline.

7. Switching Branches

Command: git checkout

What It Does: Switches between branches. It’s like flipping through different pages of your scrapbook to work on various parts of your project.

8. Merging Changes

Command: git merge

What It Does: Combines changes from different branches. Imagine merging two scrapbooks into one, ensuring all your favourite moments are captured together.

9. Cloning a Repository

Command: git clone

What It Does: Creates a copy of an existing repository. Perfect for starting work on a project that already exists.

10. Pushing to a Remote

Command: git push

What It Does: Uploads your local changes to a remote repository. Think of it as sharing your scrapbook online for everyone to see.

11. Pulling Changes

Command: git pull

What It Does: Fetches and merges changes from a remote repository to your local repository. Stay updated with the latest scrapbook pages from your friends.

12. Resolving Conflicts

Command: Manually resolve conflicts, then use git add and git commit

What It Does: Sometimes, merging can cause conflicts. You’ll need to resolve these by editing the conflicting files, then staging and committing the resolved files.

13. Viewing Differences

Command: git diff

What It Does: Shows the differences between commits, branches, or your working directory and the repository. Like spotting differences between scrapbook pages.

14. Rebasing Branches

Command: git rebase

What It Does: Reapplies commits on top of another base tip. This command is useful for maintaining a clean project history by integrating changes from one branch into another.

Wrapping Up

Git might seem like a complex tool, but once you get the hang of these essential commands, you’ll find it incredibly empowering. Version control, collaboration, and project management become a breeze.