Git commands - Hyp-ed/hyped-2024 GitHub Wiki
This is only necessary the first time you need to download the repo to a new device
git clone <ssh-url> - download the repo at <ssh-url> from github
(n.b. throughout this page wherever you see <text> you replace all of <some-text> with some argument (< and > included))
e.g. to clone the hyped-2024 repo you run [email protected]:Hyp-ed/hyped-2024.git
- 
git checkout master- checkout the main branch of the repo
- 
git pull- downloads changes from github to bring your local copy of the repo up to date with the remote repo
- 
git branch <name-of-branch>- create a new branch named<name-of-branch>
- 
git checkout <name-of-branch>- move to the branch you just created
- 
git add <files>- stages the files to be included in the next commit (note that you can use.to stage all files in your present working directory)
- 
git commit -m "<commit-message>"- create a new commit.<commit-message>should be a description of what that commit changes
- 
git push- upload your changes to github
- The first time you work on a branch: open a PR on github
- Wait for reviews on your PR
- Fix issues raised in reviews
- Repeat until your PR is approved
- Click "Squash and Merge" on your PR
git status - lists unstaged changes, staged changes, and the difference between your local branch and the remote branch
git log - lists all previous commits
git restore --staged <files> - unstages added changes that have not yet been committed
git revert HEAD~<n> - creates a new commit that undoes the previous <n> commits
git diff HEAD~<n> - gives the difference between the head of the branch and the commit <n> commits ago
(n.b. in each place I use <HEAD~<n>> you can also use a commit ID, which is found using git log)
These commands are fine to use if you haven't pushed the offending commits to github, if you have then you shouldn't use these
git reset HEAD~<n> --soft - deletes last <n> commits from your branch, keeps the changes they made to files staged
git reset HEAD~<n> --hard - deletes last <n> commits from your branch, and removes the changes to the files
git rebase -i - interactive rebase, lets you change the historical commits on your branch. This has more options than I can document here, and if you use it you are responsible for the mess you make