Andy Van Slaars

Andy Van Slaars

moon indicating dark mode
sun indicating light mode

git stuff for lookup purposes

Interactive rebase

Start rebase

git rebase -i HEAD~5 - where 5 is the number of commits to go back

For Edit

  1. Change pick to edit or e for the commits you want to edit

    • i to switch to insert mode in vim
  2. Save file

    • esc then :wq to write file in vim
  3. Make changes to code

  4. Save code changes

  5. Stage changes git add <filepath>

  6. Continue git rebase --continue

Push a specific commit to a remote

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>

Fork your own repo

I found these instructions in this blog post on TIL

  1. Create a new, empty repo
  2. Clone it locally
  3. Add an upstream remote - git remote add upstream <Orig Repo Url>
  4. Pull from the upstream remote - git pull upstream master

Sync upstream changes

Assuming you have a fork and want to pull changes from the upstream repo.

  1. Fetch upstream changes - git fetch upstream
  2. Checkout master (or whatever branch you want to merge upstream changes into)
  3. Merge in upstream changes - git merge upstream/master
  4. Profit

Assign a tag to a new commit

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"

Create branches from tags

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>