GIT Cheat Sheet
July 2020
I recently started coding on two different computers, as my trusty Surface Book 2 has been joined by a Mac Mini. Among other advantages, this new setup has made me more disciplined about using GIT properly and consistently, so I can always have my code in sync between the two local environments.
The result of this newfound regimen is the following cheat-sheet.
Adding a Local Project to GIT
cd name-of-my-local-project-foldergit initgit remote add origin https://github.com/stepicker/name-of-my-project.git
Updating a Github Repo with Local Changes
git add .git commit -m "Description of the commit"git push origin master
Using Branches
git branch # See available branches, and which one we are ongit branch new-branch # Create a new branchgit checkout new-branch # Switch to new-branchgit add .git commit -m "Description of the commit"git push origin new-branch # Push new-branch to the remote repo
After that, there are two main ways to merge a branch into master.
Locally:
git checkout master # Switch to the master branchgit merge new-branch # Merge new-branch into the current branch (in this case: master)git push origin master
On the Github web site, where I usually pick "squash & merge" after opening a pull request. After that, either one of my machines can get the latest code with:
git pull origin master
I must admit that — after experiencing some early pain with merge conflicts during my Bootcamp — I spent a few months relishing the simplicity of only using master
and having full control over it.
However, as the complexity and size of my projects grew, I now take full advantage of branches to clearly identify and manage feature sets. Yes, it makes sense even on individual projects without collaborators.