|
|
## Basics
|
|
|
|
|
|
- branches
|
|
|
- Repository setup
|
|
|
```
|
|
|
git fetch -a //fetch branches
|
|
|
git branch -a //list all branches, -r only remote
|
|
|
git checkout -b branch_name //create new local branch
|
|
|
git push -u origin branch_name //push the local branch to origin
|
|
|
git clone --recurse-submodules <URL> // Fetch and clone a remote repository
|
|
|
```
|
|
|
|
|
|
- commit
|
|
|
- Utlities
|
|
|
```
|
|
|
git commit -a //commit all change files
|
|
|
git checkout -- *file* //revert changes made to that file
|
|
|
git reset head //reset all to the last commit (--hard to force)
|
|
|
git log // View local commit history
|
|
|
git status // View tracked/untracked files, and staged changes
|
|
|
```
|
|
|
|
|
|
- stash changes
|
|
|
- Registering local changes
|
|
|
```
|
|
|
git stash
|
|
|
git stash --apply
|
|
|
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 shit" moments
|
|
|
```
|
|
|
git checkout -- <FILE> // Reset changes to a specific file
|
|
|
git merge --abort // Abort a merge if there are any conflicts
|
|
|
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
|
|
|
```
|
|
|
git merge <BRANCH> // Merge branch into the current one
|
|
|
git rebase <BRANCH> // Move all of the current commits to the top of branch
|
|
|
```
|
|
|
|
|
|
- undo last local commit
|
|
|
- Stashing
|
|
|
```
|
|
|
git reset [--hard] HEAD~
|
|
|
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
|
|
|
```
|
|
|
|
|
|
## Submodules
|
|
|
|
|
|
- Create a submodule
|
|
|
```
|
|
|
git submodule add https://github.com/name/repo
|
|
|
```
|
|
|
```
|
|
|
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
|
|
|
```
|
|
|
```
|
|
|
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:
|
|
|
|
... | ... | @@ -63,15 +95,15 @@ |
|
|
|
|
|
- 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
|
|
|
``` |
|
|
\ No newline at end of file |
|
|
```
|
|
|
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
|
|
|
``` |
|
|
\ No newline at end of file |