Last active
August 24, 2024 00:07
-
-
Save AndrewSepic/ddf184728d69d17a8ef94844d3f05a97 to your computer and use it in GitHub Desktop.
A list of my most used git commands for reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
// Revert the changes of a specific file from a previous commit | |
git checkout <commit-hash> -- <file-path> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment