Skip to content

Instantly share code, notes, and snippets.

Last active January 26, 2022 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdv24/43b90df359715c36393a83fdb15f571e to your computer and use it in GitHub Desktop.
Save kdv24/43b90df359715c36393a83fdb15f571e to your computer and use it in GitHub Desktop.

Commands I use but don't always remember:

nvm alias default <branch_number>: makes it so you don't have to repeatedly set the node version

git push --force-with-lease: doesn't overwrite anything the way git push -f does

git rebase -i HEAD~30 : allows you to modify your last 30 commits (squash, delete, edit, etc) one at a time

git pull -r origin master (same as git pull --rebase origin master) : rebases your current branch on the specified branch at the same time as pulling the current state of the specified branch

git merge --ff-only origin <branch-to-merge-in> merges only if applying the changes on top won't cause any conflicts. Run from on the branch you want to merge to.

git bisect : amazing command that allows you to find where your code broke by specifying the commit where it works (the good commit) and where it is broken (the bad commit). git bisect then repeatedly splits the commit history between the two and you identify whether it is good or bad until you find the offending commit

git config --global pull.ff only will tell git to only pull if it is a fast forward pull. This will stop accidental merges.

  • That is the config command,
  • --global means it will be your global git config. If you omit the global flag then it will only affect your current git project. You can pass --rebase, --no-rebase, or --ff-only on the command line to override the configured default per invocation.
  • pull has a few options: pull.rebase false (default) does a merge, pull.rebase true will assume the --rebase flag when pulling, and pull.ff which will rebase in fast forward only fashion.

rename a branch:

git branch -m <new-name>

create a new branch from a remote branch:

git checkout -b <name_of_new_branch> origin/<name_of_branch_to_come_from>

git stash save setup_changes (to name a git stash for later)

  • to apply do git stash <name> apply

set your branch to exactly match the remote branch:

If you want to save your current branch's state before doing this (just in case), you can do:

  • git commit -a -m "Saving my work, just in case"
  • git branch my-saved-work

Now your work is saved on the branch "my-saved-work" in case you decide you want it back (or want to look at it later or diff it against your updated branch).

Note that the first example assumes that the remote repo's name is "origin" and that the branch named "master" in the remote repo matches the currently checked-out branch in your local repo.

  • git fetch origin
  • git reset --hard origin/master

tell git to ignore changes to a file

git update-index --assume-unchanged <file_name>

use curl to grab a file and output it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment