The simplest git workflow for people who hate git is the “commit, push, pull” loop: you make changes, commit them with a short message, and push to a remote repository. You only need four commands (git add, git commit, git pull, git push) and you never touch branches, merges, or rebases unless you absolutely have to.
Why This Workflow Works
Most people who hate git dislike it because they were taught branches, merges, and conflict resolution before they even understood why version control is useful. This workflow strips git down to its core purpose: keeping a history of your changes and syncing them to a backup location.
You work on one branch (usually called main or master), and you never create feature branches. You commit whenever you finish a logical chunk of work, and you push to the remote so your work is safe. When you start a session, you pull to get any changes your teammates made. That’s it.
This is sometimes called the “trunk-based” workflow, though in its simplest form it doesn’t even use the formal practices of trunk-based development. It’s just a single shared branch that everyone pushes to.
How to Set It Up
If you’re starting from scratch, here are the steps:
- Install git on your computer.
- Create a repository on a hosting service like GitHub, GitLab, or Bitbucket.
- On your computer, run
git initin your project folder, or clone the remote repository withgit clone <url>. - Add your files with
git add .(orgit add filenamefor specific files). - Commit with
git commit -m "your message". - Push with
git push.
If you cloned, git already knows where the remote is. If you ran git init, you need to add the remote with git remote add origin <url> before pushing.
When to Commit and Push
The golden rule is: commit often, push at least once a day. A good commit is one that contains a logical unit of work—like “fix typo in header” or “add login form”. You don’t need to write a novel in the commit message; a short phrase that describes what you changed is enough.
Push whenever you’re done for the day, or whenever you want a backup. If you’re working with others, push before you take a break so they can pull your changes. The remote is your safety net: if your laptop dies, your work is still there.
What to Do When You Get a Conflict
Conflicts happen when two people change the same line in the same file, and git can’t decide which version to keep. When you run git pull and get a conflict, git will mark the file with both versions. You open the file, look for the markers <<<<<<<, =======, and >>>>>>>, and manually edit the file to keep the correct version. Then you save, run git add on that file, and git commit.
Conflicts are rare if you work on different files, and they’re not something to fear. They’re just git telling you that two people changed the same thing. The fix is always the same: open the file, decide what it should say, and commit.
Common Mistakes and How to Avoid Them
- Forgetting to pull before you push: If you push and get a “non-fast-forward” error, it means someone else pushed since your last pull. Just run
git pulland thengit pushagain. - Committing sensitive data: Never commit passwords, API keys, or personal files. Add a
.gitignorefile to exclude them. If you accidentally commit one, you need to remove it from history, which is more advanced. - Using vague commit messages: “stuff” or “changes” are not helpful. Write what you actually did: “update contact info” or “fix broken link”.
- Committing large binary files: Git is not great at handling big files like videos or datasets. Keep them out of the repo if possible, or use a separate tool like Git LFS.
What If You Need to Undo Something?
Even with a simple workflow, you’ll sometimes make a mistake. The most useful undo command is git restore filename, which discards changes to a file since your last commit. If you’ve already committed but want to undo that commit, use git reset --soft HEAD~1 to uncommit but keep your changes, or git reset --hard HEAD~1 to completely discard the last commit. Be careful with --hard: it permanently deletes the changes.
If you’ve already pushed a bad commit, the simplest fix is to make a new commit that reverts it. Use git revert HEAD to create a commit that undoes the last one. This is safe because it doesn’t rewrite history.
Frequently Asked Questions
Do I need to use branches?
No. For solo projects or small teams, a single branch is fine. Branches are useful when you need to work on a big feature without breaking the main code, but they add complexity. Start without them and only introduce branches when you feel the need.
What’s the difference between git pull and git fetch?
Git fetch downloads the latest changes from the remote but doesn’t merge them into your working files. Git pull does both: it fetches and then merges. For this workflow, just use git pull.
How do I ignore files I don’t want to commit?
Create a file named .gitignore in your project root. Add patterns like node_modules/ or *.log to ignore folders or file types. Git will then skip those files when you run git add.
What if I accidentally commit a file with sensitive information?
If you haven’t pushed yet, you can use git reset --soft HEAD~1 to uncommit, then add the file to .gitignore and recommit. If you’ve already pushed, you need to remove the file from history, which is more complex. The safest method is to rotate the credential (change the password or key) and then remove the file from the repo.
Why does git ask me to configure my name and email?
Git attaches your name and email to every commit so people know who made the change. You only need to set it once with git config --global user.name "Your Name" and git config --global user.email "you@example.com".
Can I use git without a remote repository?
Yes, you can use git locally for version control, but you lose the backup and collaboration benefits. The remote is what makes git powerful, so it’s worth setting up even for solo projects.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Best Family Western Movies to Stream Right Now
- Luxury V6 Sports Sedan: Can It Easily Top 100k Miles?
- Puppets in TV Shows: Classic Proof They’re Better
- Best Streaming Remote: Top Picks for Every Setup
- Claude Pro Hidden Features Power Users Try
- Tesla Rental Prices: Why They’re So Low255.00 USD