-
Notifications
You must be signed in to change notification settings - Fork 1
Git Cheat Sheet
Michael Shipman edited this page Feb 9, 2024
·
2 revisions
- Check what files have been changed
git status
- Stage file, directories, or all changes for a commit
git add . //current directory
git add /path/to/file
git add ./directory
git add --all //all changes
- Commit changes with message
git commit -m "message"
- Push changes
git push
git fetch
git checkout remote/current-branch /path/to/file
git pull
- To remove files from staging, but keep your changes:
git reset HEAD <file>
- To unstage the last three commits:
git reset HEAD^3
- To unstage changes to a certain file from HEAD:
git reset <filename>
After you unstage the file, to revert the file back to the state it was in before the changes:
git checkout -- <file>
- List all branches (the one you are currently in is marked)
git branch -a
- Switch branches
git checkout branch-name
Many of the repositories that you might be working on have git submodules in them. Submodules are just a convenient way of including other repositories in another repository. After you clone a repository with submodules in it run git submodule update —init —recursive
to initialize all the submodules (basically clones all of them down for you).
Critically, if you make changes to files in a submodule that you want to push back to Github you need to first make sure that you are tracking the proper branch for that repository.
# Enter the directory for the submodule
cd /path/to/submodule
# Change to the branch you want (probably main)
git checkout branch-name
# From here make changes, add, commit, and push