Git(Hub) Cheatsheet
Pull code
git pull
Downloads the latest changes from GitHub. Make sure you do this before you make a new branch or start a coding session, to prevent syncing issues later.
View the current branch
git branch
Displays the list of branches and the current one.
Change the current branch
git checkout <branch>
Switches to branch
.
Create a branch
git checkout -b <new-branch>
Creates the branch new-branch
and switches to it. This branch forks whatever branch you’re currently on. The branch names should generally follow these formats:
feature/<issue-name>
(for adding a new feature)bugfix/<issue-name>
(for fixing a bug)hotfix/<issue-name>
(for urgent fixes, e.g. security patches)
Commit code
git commit -am "<commit message>"
Commits all changes to the code, with the summary message commit message
. This creates a new version in the git history, which is important if you need to rollback at some point. It also allows you to publish your changes to GitHub.
In the commit message, always include the ID of the ticket you are workign on at the start of the message.
Push code
git push
Uploads your changes to GitHub.
If GitHub doesn’t know about the branch yet, you may need to run this:
git push -u origin <new-branch>
Make a pull request
A pull request (or more intuitively, a merge request), allows other people to review your code before it’s merged back into the main branch (dev
). You can do so by visiting our GitHub repo in your browser, then going to the “Pull requests” tab, clicking “New pull request”, and selecting your branch. You can then add reviewers, which should include the team lead and other relevant people on the team (e.g. frontend people if it’s a frontend feature).