This article provides a quick reference to the essential commands you'll need when using Git and GitHub to contribute to MDN. If you are new to these tools and need a helping hand, our GitHub for complete beginners tutorial teaches the basics.
git clone the-repo-url
git remote add remote-name repo-you-want-to-point-to
git remote -v
git switch main
git fetch remote-name git rebase remote-name/main git push
git pull git switch new-branch
git add path-to-changed-file git commit -m 'my commit message' git push
git restore file-path
git restore --staged file-path
git reset HEAD~1
git revert HEAD git push
Another way to handle getting rid of files that have ended up in pull requests that you don't want to be there is to use the GitHub UI. Go to your pull request's page on github.com, go to the "Files changed" tab, and find the file you want to remove from the pull request. At the top right of the file's box in the page there will be a "three dot" (
...) menu. Press this button and choose "Delete file". In the confirmation page, enter a title for the new commit, make sure the "Commit directly..." checkbox is selected, and press the "Commit changes" button.
If you think this cheatsheet should contain more commands, please create an issue to suggest what you think we should include.