Skip to content

Instantly share code, notes, and snippets.

@AndrewSepic
Last active August 4, 2023 20:03
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 AndrewSepic/ddf184728d69d17a8ef94844d3f05a97 to your computer and use it in GitHub Desktop.
Save AndrewSepic/ddf184728d69d17a8ef94844d3f05a97 to your computer and use it in GitHub Desktop.
A list of my most used git commands for reference
// Create a new branch from the current branch which has uncommitted work
git checkout -b <branch_name>
// Fetch all latest versions of remote & branches
git fetch -all
// Delete a local branch (forces delete with -D rather than -d )
$ git branch -D <local-branch>
// See what files were changed in a commit
git log remote_name/branch_name --raw
// See the history of a specific file over time across commits
git log --follow -p -- file_name
// Switch to a different commit - (creating a new branch and using that commit to populate it so further commits could be used)
git checkout -b my_new_branch xxxxx(commit hash)
// This will detach your HEAD, that is, leave you with no branch checked out:
git checkout 0d1d7fc32
// Or if you want to make commits while you're there, go ahead and make a new branch while you're at it:
git checkout -b old-state 0d1d7fc32
// Revert to a previous commit
// This will destroy any local modifications.
// Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32
// This will unstage all files you might have staged with git add:
git reset
// Revert all uncommitted changes
git reset --hard HEAD
// Update a remote URL
git remote set-url remote_name new.git.url/here
// Get History of a branch including when it was created in local time
git reflog --date=local your-branch-name
// Merge one branch into another - checkout the branch you want to merge into ie: main and then run
git merge _branchname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment