This is mainly just a list of git commands for my own reference
{COMMIT_HASH}
: the hash of a commit{N}
: a number{REMOTE}
: the name of a remote repository (most of the time the name is 'origin'){BRANCH}
: the name of a branch{PATH}
: the path to a file(s)
git commit --amend --author="John Doe <john@doe.org>"
git reset --hard HEAD^
git reset --soft HEAD^
git reset --hard HEAD~{N}
git reset --soft HEAD~{N}
git reset --hard {COMMIT_HASH}
git reset --soft {COMMIT_HASH}
See https://blog.verslu.is/git/git-rebase/ for a good explanation of rebasing.
-
Make sure you're on the branch you want to rebase.
git checkout {BRANCH}
-
Rebase interactively onto a desired branch.
git rebase -i {OTHER_BRANCH}
-
Go through the required steps to rebase (picking commits, resolving merge conflicts, etc).
-
Force push the branch (only this single branch) to overwrite the remote copy.
git push origin {BRANCH} -f
git reset --soft HEAD~{N}
git commit -m "Your message"
Force push to the origin
git push origin +{BRANCH}
Check if you have the upstream remote setup.
git remote -v
If not, then set up the upstream.
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
Fetch the changes from the upstream.
git fetch upstream
Make sure you're on your local master branch.
git checkout master
Merge the changes into your local repo's master branch.
git merge upstream/master
Push the changes to the origin remote.
git push origin master
git checkout --track {REMOTE}/{BRANCH}
git push --delete {REMOTE} {BRANCH}
git branch -d {BRANCH}
To untrack files that have already been committed (if you don't want to just straight up delete them)
Add the files to your .gitignore.
Run git rm --cached {PATH}