Last active
October 28, 2021 21:00
-
-
Save rreece/e91dc60ad665dd5ab5fbea5662048c79 to your computer and use it in GitHub Desktop.
git tricks i always forget
This file contains 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
git clone git@github.com:GitUserOrOrg/repo.git | |
# create a new branch | |
git checkout -b rreece/branch1 | |
# set my branch to track the master when i do git pull | |
#git branch --set-upstream rreece/branch1 origin/master # deprecated | |
git branch --set-upstream-to origin/master | |
# 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 master with the checked-out branch: | |
git fetch origin | |
git merge origin/master | |
# manually fix CONFLICTS by hand, then commit and push | |
git commit -a -m "fixes after merge master" | |
git push origin rreece/branch2 | |
# rebase method of catching up with master | |
git checkout master | |
git pull | |
git checkout rreece/branch | |
git rebase -i master | |
# follow directions to pick and squash | |
git push -f origin rreece/branch | |
# how to permanently delete from git history | |
# https://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-git-repo | |
# remove dir from master | |
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 master --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