Some git commands outside of the most basic of basics usage of git. Thumbnail courtesy Discord member A Soulful Horse Portrait.
Git and other version control systems are pretty useful, especially if you’re working on multiple computers and perhaps with other collaborators. They let you keep track of who has accomplished what and at what time, as well as keeping a history of all your changes, so that you can always go back into your development history and take a peek or revert some changes. As nice-sounding and magical as it sounds, git can be a scary landscape to navigate. Some of the most basic commands we need to be able to use git are:
git add .
git commit -m '<some sort of message of progress>'
git push
git checkout
git fetch
git pull
Assuming we’re only working on a single master
branch (let’s not get into the topic of branches now…), this basic commandset usually works alright. The trouble arises when there’s a merge conflict
. This happens when you try to git pull
from the branch, and there are some changes that happened earlier that are incompatible with your current changes. You have a couple options to resolve this merge conflict issue:
git checkout <branch_name> <file_name>
. Overwrite your progress with the file’s state that is currently in the history of the branchgit checkout --patch <branch_name> <file_name>
. Pull the file from the branch and step through it, choosing which of your changes you want to keep and which of the branch’s file is correct.git stash; git pull
. Stash your changes into some local history so that you can pull from the branch and overwrite your local changes, but then later you can dogit stash apply
to get your work back.git fetch --all; git reset --hard <branch_name>
. Force your local branch to be overwritten with the history-tracked-branch. Similar to the first command, but it will update the entire repository, not just individual files.- and…probably a whole host of other options that are too advanced for us to know how to use.
We only just recently learned about these commands, but they are saving many hairs from being pulled out in frustration. With these new commands, we can now start to figure out how to navigate the whole branches
landscape, but that’s a topic for another day, complete with pictures and referrals to other people’s blogposts.