Basics
-
Repository setup
git clone --recurse-submodules <URL> // Fetch and clone a remote repository
-
Utlities
git log // View local commit history git status // View tracked/untracked files, and staged changes
-
Registering local changes
git add <FILE> // Stage local file for commit git rm <FILE> // Remove a local file (both physically and for git) git mv <FILE> // Move a local file (both physically and for git) git commit -m <MSG> // Commit all staged changes, with (not)optional message
-
"Oh sh*t" moments
git checkout -- <FILE> // Reset changes to a specific file git merge --abort // Abort a merge if there are any problems git rebase --abort // Abort a rebase if there are any problems git reset <HASH> // Soft reset to given hash (only removes commit) git reset --hard <HASH> // Hard reset to given hash (also removes all physical changes) // Use HEAD~ in place of hash to reset last commit
-
Syncing to remote
git pull // Recover all changes from remote repository (ALWAYS DO THIS BEFORE PUSH!) git push origin <BRANCH> // Push local changes to remote branch
-
Branches
git checkout <BRANCH> // Switch to branch git checkout -b <BRANCH> // Switch and create a branch git fetch -a // Fetch branches git branch -a // List all branches, -r only remote git checkout -b <BRANCH> // Create new local branch git push -u origin <BRANCH> // Push the local branch to origin
-
Merging/rebasing
git merge <BRANCH> // Merge branch into the current one git rebase <BRANCH> // Move all of the current commits to the top of branch
-
Stashing
git stash // Stash current changes git stash pop // Restore stashed changes, and remove them git stash apply // Restore stashed changes, without removing them git stash clear // Remove all stashes git stash list // List all stashes
Submodules
-
Create a submodule
git submodule add https://github.com/name/repo
-
Update submodule: If there's a new commit on a submodule that you want to have in boardcore:
git submodule sync git submodule update --remote --init git commit
-
Update miosix-kernel fork: If you want to pull in skyward-er/miosix-kernel the commits that were made in the original repo (fedetft/miosix-kernel), you have to do two things:
- Clone skyward-er/miosix-kernel and in it:
git fetch upstream git merge upstream/testing git push
- In skyward-boarcore:
git checkout testing git submodule update --remote git commit git push
-
Push commits from within submodule: In general, if you want to modify a submodule (e.g. modifiy mavlink_skyward_lib from Mavlink_editor or skyward-boardcore).
cd submodule-folder git checkout master git pull <modifiy> git add <file-modified> git commit // commit updates inside the submodule git push cd ../.. git submodule update // the submodule folder now points to latest version git commit // commit the update of the submodule reference