Last active
February 17, 2025 23:09
-
-
Save rreece/e91dc60ad665dd5ab5fbea5662048c79 to your computer and use it in GitHub Desktop.
git tricks i always forget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # clone a repo | |
| git clone git@github.com:GitUserOrOrg/repo.git | |
| # create a new branch | |
| git checkout -b rreece/branch1 | |
| # set my branch to track the main when i do git pull | |
| git branch --set-upstream-to origin/main | |
| # show branches | |
| git branch | |
| # show branches tracking | |
| git branch -vv | |
| # switch branches | |
| git checkout rreece/branch2 | |
| # git commit | |
| git commit -a -m "a commit msg" | |
| # git push to your branch | |
| git push origin rreece/branch2 | |
| # make a sub-branch from a branch | |
| git checkout -b rreece/subbranch rreece/branch2 | |
| # undo uncomitted changes to a file and get the head version of the current branch | |
| rm -f FILE | |
| git checkout -- FILE | |
| # check for commits that haven't been pushed | |
| git log --branches --not --remotes | |
| # how to merge main with the checked-out branch: | |
| git fetch origin | |
| git merge origin/main | |
| # manually fix CONFLICTS by hand, then commit and push | |
| git commit -a -m "fixes after merge main" | |
| git push origin rreece/branch2 | |
| # rebase method of catching up with main | |
| git checkout main | |
| git pull | |
| git checkout rreece/branch | |
| git rebase -i main | |
| # follow directions to pick and squash | |
| git push -f origin rreece/branch | |
| # how to add a submodule | |
| git submodule add https://github.com/rreece/hepplot hepplot | |
| git status | |
| git commit -a -m "add hepplot submodule" | |
| git push origin main | |
| # how to update submodules | |
| git submodule update --init --recursive | |
| # how to permanently delete from git history | |
| # https://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-git-repo | |
| # remove dir from main | |
| git filter-branch --tree-filter 'rm -rf GitUserOrOrg/repo/data/' HEAD | |
| # remove badfile from all branches | |
| git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch GitUserOrOrg/repo/data/badfile' --prune-empty --tag-name-filter cat -- --all | |
| # always end with | |
| git push origin main --force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/33503080/learning-git-tracking-vs-setting-upstream-u-for-remotes