git rebase -i HEAD~5 - where 5 is the number of commits to go back
efor the commits you want to edit
ito switch to insert mode in vim
:wqto write file in vim
Make changes to code
Save code changes
git add <filepath>
git rebase --continue
Sometimes, you want to push a specific commit on a branch, not the most recent commit. For me, this is typically because I have worked through code for a lesson and want to push an early commit to a repo as a starting point for people to follow along.
git push <remotename> <commit SHA>:<remotebranchname>
I found these instructions in this blog post on TIL
- Create a new, empty repo
- Clone it locally
- Add an upstream remote -
git remote add upstream <Orig Repo Url>
- Pull from the upstream remote -
git pull upstream master
Assuming you have a fork and want to pull changes from the
- Fetch upstream changes -
git fetch upstream
master(or whatever branch you want to merge upstream changes into)
- Merge in upstream changes -
git merge upstream/master
After a rebase, tags will continue to point to their original, old commits.
Sometimes you tag something then make a minor change in a new commit and want to move the tag up one commit.
Remove the tag from your remote (if pushed):
git push origin :refs/tags/12345
or the sorter version:
git push origin :12345
Simply apply the tag as you would, but add the
f flag to force it
git tag -af <tagName> -m "Tag message"
Or to move the tag to a specific commit:
git tag -af <tagName> <COMMIT SHA> -m "Tag message"
This one is pretty straight-forward, but I always second guess myself when I haven’t done it in a while.
git checkout -b <Branch> <Tag>