Last active
September 3, 2019 17:19
-
-
Save nlitwin/931b0cbbdf323fe795a2 to your computer and use it in GitHub Desktop.
Useful Git Commands
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
# Revert to a previous commit | |
git reset --hard commit_sha | |
# Create a local branch which tracks from an already created remote branch | |
git co --track -b branch_name origin/branch_name | |
# Push local branch to a remote branch with a different name | |
git push origin local-name:remote-name | |
# If you want to rename a branch while pointed to any branch | |
git branch -m <oldname> <newname> | |
# If you want to rename the current branch | |
git branch -m <newname> | |
# List all remote branches | |
git branch --remote --list | |
# If repository name changes, change the remote origin | |
git remote | |
git remote show origin | |
git remote rm origin | |
git remote add origin https://github.com/user/repo_name.git | |
# See diff between two branches | |
git diff branch_1..branch_2 | |
# That will produce the diff between the tips of the two branches. | |
# If you'd prefer to find the diff from their common ancestor to test, you can use three dots instead of two: | |
git diff branch_1...branch_2 | |
# Search content of old commits | |
git grep <regexp> $(git rev-list --all -- my/sub/directory) -- my/sub/directory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment