DEV Community

Cover image for 50 Git Commands I Use Everyday as a Dev
Josh the Coder
Josh the Coder

Posted on

50 Git Commands I Use Everyday as a Dev

As a developer, I'm always juggling code, making sure it's neat and gets where it needs to go. Git is like my digital toolbox – it's full of commands that help me manage my code efficiently. Let's dive into 50 of these commands that I use pretty much every day.

Basic Setup and Config

git init

What it does: It's like planting a seed that grows into a new Git repository. Use this when you're starting a brand new project.

git clone [url]

What it does: Think of it as copying someone else's project so you can work on it too. You just need the project's URL.

git add [file]

What it does: This command is like telling Git, "Hey, keep an eye on these files." It stages your files for commit.

git commit -m “[commit message]”

What it does: It’s like putting a sticky note on your changes, saying, "I did this." Helps you and others know what you changed and why.

git status

What it does: Gives you the lowdown on what's happening with your files – which ones are changed, which are ready to be committed, etc.

git config

What it does: Set up your Git environment. It's like adjusting the settings on your TV to get the picture just right.

Branching Out

git branch

What it does: Lists all the branches in your repository. Branches are like parallel universes for your code.

git checkout [branch-name]

What it does: Moves you to a different branch. It's like hopping between those parallel universes.

git merge [branch]

What it does: Brings the contents of another branch into your current branch. Imagine merging two rivers into one.

Working with Remotes

git remote add [name] [url]

What it does: Connects your local repo to a remote one. It's like saving a contact in your phone.

git fetch [remote]

What it does: Grabs all the changes from the remote but doesn't merge them. Like window shopping for code.

git pull [remote]

What it does: Fetches the remote changes and merges them. It's like fetching a toy your dog wants and then giving it to him.

git push [remote] [branch]

What it does: Sends your local branch updates to the remote repository. Think of it as uploading your latest selfie to Instagram.

Checking History

git log

What it does: Shows a log of all the commits. It's like a diary for your project.

git diff

What it does: Shows the changes between commits, commit and working tree, etc. It's like playing "spot the difference" with your code.

git reset [commit]

What it does: This command is like a time machine; it takes your project back to an earlier state.

Advanced Stuff

git stash

What it does: Temporarily shelves (or stashes) changes you've made to your working copy so you can work on something else.

git tag [commitID]

What it does: Marks a specific point in history. It's like putting a bookmark in your code.

git rebase [branch]

What it does: It's a bit like cutting a piece of a branch off a tree and attaching it somewhere else.

git cherry-pick [commit]

What it does: Takes the changes from a single commit in another branch and applies them to your current branch.

Just in Case!

git revert [commit]

What it does: If you mess up, this command creates a new commit that undoes all of the changes from a previous commit.

git blame [file]

What it does: Shows who last modified each line of a file. It's like detective work for finding who last touched a specific part of the code.

git bisect

What it does: Helps you find the commit that introduced a bug by using a binary search.

Clean Up and Maintenance

git gc

What it does: Cleans up unnecessary files and optimizes your local repository.

git fsck

What it does: Checks the integrity of your Git file system and can find corrupted objects.

There are many more commands, but these are the ones I find myself using almost daily. Remember, the best way to learn Git is by using it. So don't be afraid to dive in and start tinkering with these commands!

Top comments (3)

perssondennis profile image
Dennis Persson

Good summary for people who have just learnt about git.

But 50? Does your counting include all the times you misspell the commands?

jangelodev profile image
João Angelo

Great Josh, thanks for sharing!

shameel profile image
Shameel Uddin

I am doing coding for number of years and I only remember where I "might" have used 50 commands in a single day when I messed up with my git repo lol.

Btw, it's a really nice list. =D