These notes are intended to be used and studied in tandem with Chris Achard's course.
If you notice areas that could be improved please feel free to open a PR!
-
๐จThese notes use the Night Owl Theme color palette.
-
๐Download a PDF copy here!.
-
๐Checkout the Sketch files here.
- Change commit messages
- Add or remove files from a commit
- How and when to stash changes
- What a "detached HEAD" is, and how to fix it
- Remove secrets from a codebase
- How to rewrite history
git commit --amend -m "New message"
# only do this BEFORE you've pushed the commits
git add -A
git commit --amend -m "My new message"
git reset HEAD filename
# reset back to a specific commit
git reset HEAD~1
# or
git reset [HASH]
# Resets the index and working tree
git reset --hard [commit]
# Does not touch the index file or the working tree at all
git reset --soft [commit]
# Resets the index but not the working tree
# Reports what has not been updated
# This is the default action
git reset --mixed [commit]
# To look up the commit hash
git reflog
git reset --hard [HASH]
# NOTE: Once a commit is pushed, you do NOT want to use git reset
# make a "revert commit" which will "undo" a specific commit
git revert [HASH-TO-UNDO]
git checkout -b new-branch
git push
# set the upstream of the local branch at the same time
git push --set-upstream origin new-branch
git cherry-pick [HASH-TO-MOVE]
# Get the commit we want
git cherry-pick [HASH-TO-MOVE]
# Remove the commit from the wrong branch
git reset [HASH-TO-REMOVE]
# Save the local changes,
git stash
# Get remote changes
git pull
# To apply the stashed changed
git stash pop
# You will need to fix the merge conflict
# Then drop the change from the stash
git stash drop stash@{0}
# checkout the hash of an old commit
git checkout [HASH]
# we'll be in a "detached HEAD" state
# Save the work by creating a new branch
git checkout -b my-new-branch
git checkout -b conflicts_branch
# Add 'Line4' and 'Line5'
git commit -am "add line4 and line5"
git push origin conflicts_branch
git checkout master
# Add 'Line6' and 'Line7'`
git commit -am "add line6 and line7"
git push origin master
# use the github interface to delete the branch remotely
# Locally
# Confirm that remote is gone
git remote prune origin --dry-run
git remote prune origin
#clean up the feature branch
git branch -d feature-branch
git log --oneline
# start the interactive rebase
git rebase -i HEAD~3
# and then change pick to reword.
# We can now reword the commit message
# We make a file and accidentally push it to github
# To remove it, add it to .gitignore file
# remove all of our files from our git cache
git rm -r --cached .
# add back all the files we want with
git add -A
git rebase -i HEAD~2
# during the interactive rebase, we can add the file, and amend the commi
git commit --amend --no-edit
git rebase --continue
# ennter interactive rebase
git rebase -i HEAD~2
# Then we can fix that merge conflict like normal, but finish up the rebase
git rebase --continue
git rebase -i HEAD~3
# Make the changes in interactive rebase
# Make the commit message for that commit, and once we save the message
# we'll be left with just a single commit
# prune the entire history and garbage collect the remains
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# use git push to push that change to github,
# and remove the .env file from all of the history