You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
git push --delete <remote_name> <branch_name>
git branch -d <branch_name>
git branch -D <branch_name> # Force delete of branch
Rename branch
1. Rename your local branch.
If you are on the branch you want to rename:
git branch -m new-name
If you are on a different branch:
git branch -m old-name new-name
2. Delete the old-name remote branch and push the new-name local branch.
git push origin :old-name new-name
3. Reset the upstream branch for the new-name local branch.
Switch to the branch and then:
git push origin -u new-name
Modify a commit message
git commit --amend
Working with tags
git tag [tag_name]
git tag -a v-1.0 # Create an annotated tag
git tag v-1.2 -m "Release 1.2" # Create an annotated tag with description
git push origin v-1.0 # Push specyfic tag
git push origin master --tags # Push local tags to remote origin
git tag --list # See tags
git show [tag_name] # Show tag
git tag --delete [tag_name] # Delete tag
git push origin :v-1.0 # Delete an already pushed tag on remote (push nothing to that tag)
git difftool v-1.0 v-1.1 # Comparte two tags
git tag -a v-0.9-beta 96ef2812 # Create a tag for specyfic commit
git tag -a v-0.9-beta 9689516a # Associate an existing tag to different commit
Working with stashes to save work in progress
git stash save "my_stash"
git stash list
# To apply a stash and remove it from the stash stack, type:
git stash pop stash@{n}
# To apply a stash and keep it in the stash stack, type:
git stash apply stash@{n}
git stash drop # Drops last stash
git stash show stash@{0} # See files modified on a specyfic stash
git stash -u # Stashes including the untracked files on working directory, not only the files tracked by git
git stash clear # Remove all saved stashes
git stash branch newbranch # Creates a new branch 'newbranch', switches to it, and applies last stash to it
Open .gitconfig file to see global git configurations
Unstage/revert local changes added to staging area
git reset HEAD file.txt
Revert to clean working directory
git checkout -- file.txt
Rename a file tracked by git
git mv file1.txt file.txt
# If renamed without git mv:
git add -A # this will make Git detect the renaming and deletions
Rename a file tracked by git
git rm file.txt
Show log history nicely
git log --oneline --graph --decorate
git log --all --graph --decorate --oneline
git log --since="3 days ago" # Show commits of last 3 days
Show details of a commit
git show 5c05047
Create alias for other git commands
git log --all --graph --decorate --oneline # Want an alias for this command
git config --global alias.hist "log --all --graph --decorate --oneline # Create an alias 'git hist' for previous command
git hist # Use it like this
git config --global -e # To see the created alias