Skip to content

Git cheatsheet

May Gan edited this page Apr 9, 2024 · 6 revisions

Summary

What I want to achieve Git command
I want to see what changes I have made git status
I want to go on a different branch git checkout [branch name] (do not include the [ ])
I want to make a new branch from the current branch git checkout -b [new-branch-name]
I want to see local branches (on my machine) git branch
I want to see remote branches (on GitHub) git branch -r
I want to add a file to staging git add [filename]
I want to add all the files I have changed to staging git add .
I want to commit my staged files git commit -m "[message goes inside double quotes without square brackets]"
I want to push my changes to GitHub so other people can access them git push (it might ask you to set an upstream branch, just copy paste the command they give you if so)
I have made changes on the wrong branch! I want to move it to the right one git stash will remove your changes in the current branch, then git checkout [branch-you-want-the-changes-to-be-in], then git stash pop will put those changes on your desired branch
I want to undo all my local changes will fill in later

Git Processes

We do not push directly to the main branch
When you work on something:

  • Check you are on the main branch using git status or git branch
    • If you are not in the main branch, do git checkout main
  • Pull the latest version of the repo with git pull
  • Make a new branch using git checkout -b new-branch-name, choose a branch name that describes what you are doing
  • The command above will also move you to the new branch, but you can double check by doing git branch
  • Once you make your changes, see your changes with git status, stage your files with git add [filename] or git add . if you want to add everything, and then finally write a commit message and commit them using git commit -m "commit message here in double quotes"
  • check you are not on the main branch (and are in your branch) by doing git branch.
  • Push your changes by doing git push, it may ask you to set upstream branch -- just follow that instruction if it does pop up
  • Now you can go on GitHub and see your branch has had recent changes pushed

** alternatively, you can make a branch from GitHub which is linked to your issue. this automatically fills out the branch name, and you will just need to checkout that remote branch on your local before starting work **

GitHub practices

  • Move your ticket/issue across the board as you go
  • When you have begun work, move your issue to "In Progress"
  • Link your branch to the issue, and commit and push regularly in case your local copy is destroyed!
  • Once you're happy with your commits and you think your work is done, make a Pull Request.
  • Move your ticket/issue to "In Review" once it is in this stage.
  • Once the Pull Request is approved (by John or May), it is your responsibility as the author to Merge it with main.
    • Please delete your branch once it has merged with main successfully (the option should pop up after you click Merge).
    • Now your changes will be updated on the main branch! Good work!!
Clone this wiki locally