git_cheatsheet
Submodules
How to properly remove submodule from git:
- Remove the submodule entry from .git/config
git submodule deinit -f path/to/submodule
- Remove the submodule directory from the superproject’s .git/modules directory
rm -rf .git/modules/path/to/submodule
- Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f path/to/submodule
Pull git submodules (ie fill directories) once you have pulled a repo, remote to local
- in root directory,
git submodule init
git submodule update
Update a submodule in Hugo Blog:
- (optional–only for forked submodules) update your main repo and push to github per usual
- in Hugo project, go into themes/ and run a
git fetch
andgit merge origin/main
- return to root folder, commit and push per usual.
General
Force pull (overide) local git with remote repo
git fetch --all
git reset --hard origin/master
(can also replace ‘master’ with another branch)
Rollback to a specific commit:
git reset --hard <old-commit-id>
(first 6 alphanum)
git push -f <remote-name> <branch-name>
Start a fresh local repo with remote github repo:
- create folder structure, including the root folder of your directory
- cd into root
git init
git remote add origin git@github.com:user/repo.git
git pull origin master
Create a new local branch from master, then push to new remote branch:
git checkout -b newbranch
- make change, add file, etc
git add . ; git commit -m "first commit newbranch" ; git push origin newbranch
Check recent commits: git log
Escape list of commits: q
Awesome resources: