Certain git commands show up in almost every workflow. Learning those first covers 90% of what you will actually need day to day. These are the commands I use most often in my own work, organized by function so the structure itself reinforces how and when to use them.
This article pairs with my Git Workflow and Git in Practice articles. I recommend reading those alongside this one.
Thanks to p4songer from the Brainfart Studio Discord for the conversation that sparked this one.
Repo-Level Git Commands
These commands connect you to a repository and keep your local copy in sync with the remote.
Starting Fresh
git init
Initializes a new Git repository in your current folder. Use this when you already have a project on your machine and want to add Git to it. From there, you connect it to a remote repository on GitHub.
git init
git clone
Copies an existing remote repository down to your local machine. The difference from init is the starting point. With clone, the repository already exists on GitHub and you are pulling it down. With init, the project exists locally first and gets pushed up.
git clone https://github.com/your-username/your-repo.git
Staying in Sync
git fetch
Checks the remote for any changes and downloads that information locally, but does not apply anything. Think of it as a knowledge update. Your files do not change. Your local repo just updates its awareness of what exists on the remote.
git fetch origin
git pull
Downloads changes from the remote and applies them to your current branch. It is fetch plus merge in one step. Your local files update to match the remote.
git pull origin development
git push
Sends your local commits to the remote. This is how your work gets to GitHub and becomes visible outside your machine.
git push origin feature/save-system
Branch Management Git Commands
These commands control which branch you are on and what branches exist.
Working With Branches
git branch
Lists all local branches. The branch you are currently on is marked with an asterisk.
git branch
You can also use git branch to create a new branch without switching to it:
git branch feature/new-system
In practice I almost never use it this way. If I am creating a branch, I want to be on it immediately. checkout -b below handles both steps at once.
git checkout
Switches to an existing branch.
git checkout development
Add -b to create a new branch and switch to it in one step. This is what I use almost every time I start new work.
git checkout -b feature/save-system
A Note on Merging
Merging is not on this list because I do not merge branches from the command line. I use pull requests for every merge, even working solo. A pull request gives you a full review before anything is finalized.
The full breakdown of why and how is in the Git Workflow article.
Commit-Level Git Commands
These commands manage the work happening inside a branch.
Tracking Your Work
git status
Shows the current state of your working directory. Which files are staged, which are modified but not staged, and which are untracked entirely. Run this constantly to check where things stand.
git status
git diff
Shows the exact line-by-line changes in your files before staging them. Use this to review what you have actually changed before committing it.
git diff *
You can also diff a specific file:
git diff Scripts/Player/PlayerController.cs
git add
Stages files for commit. The * stages everything with changes in the current directory.
git add *
You can also stage a single file if you only want part of your changes in the next commit:
git add Scripts/Player/PlayerController.cs
You may see add . used in other references. Both stage everything. * is just what I use.
git restore --staged
Unstages files without discarding the changes. Use this when you staged something by accident and want to pull it back out before committing.
To unstage everything:
git restore --staged *
To unstage a single file:
git restore --staged Scripts/Player/PlayerController.cs
Recording Changes
git commit -m
Records a snapshot of everything staged, with a message attached. The message is the record of what changed and why.
git commit -m "feat: add PlayerController with coyote time and input buffer"
Commit format and message structure are covered in full in the Git Workflow article. Short version: prefix, colon, specific description. The more specific the message, the better. You should be able to read it and know exactly what changed without opening the commit.
git log
Shows the full commit history for the current branch. Most recent commit is at the top. Use this when you need to review the history in detail.
git log
Add --oneline for a condensed single-line view per commit, useful when you need to scan a lot of history quickly:
git log --oneline
Wrapping Up
Those commands cover the majority of git commands you will use. Start or connect a repo. Stay in sync with the remote. Create branches, do the work, stage it, commit it, push it. Open a PR when the branch is done.
Most of what you need day to day lives in that list.
More Advanced Git Commands
This list is not everything Git can do. There are more commands available for more specific situations. Things like rewriting history, moving individual commits between branches, or temporarily setting work aside.
These are used much less often, but worth knowing they exist. Next week I am covering the more advanced features of Git, what each one does, and when to use them.
0 Comments