Last active
February 2, 2018 20:36
-
-
Save mauricios/ecc21016de343a33e9b06e51f0b82cbd to your computer and use it in GitHub Desktop.
Git usefull tasks
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
#!/bin/sh | |
# Delete last commit already pushed to a remote repository | |
git reset HEAD^ --hard; | |
git push origin -f; | |
# Change remote URL | |
git remote set-url origin <repo_url> | |
# Revert local changes to move back to the origin is | |
git reset --hard && git clean -df | |
# Delete local commits to remote branch | |
git reset --hard origin/master | |
# Squash commits, see: https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request#squash-your-changes | |
# Checkout the branch | |
git checkout mybranch | |
# Squash all commit messages but the older (first) one. Change all pick commits with squash/s except for the older (first) one | |
git rebase -i `git merge-base origin/$(git rev-parse --abbrev-ref HEAD) origin/master` | |
# See the history rewritten | |
git log | |
# Verify that the diff does not change | |
git diff origin/master | |
# Force push to rewrite history | |
git push -f | |
# Create and push tags | |
git tag -a <tag_name> -m "<tag_comment>" | |
git push origin <tag_name> | |
# Delete local tag | |
git tag --delete <tag> | |
# Delete remote tag | |
git push --delete <tag> | |
# Create a branch from a tag and checkout to it | |
git checkout tags/<tag_name> -b <branch_name> | |
# Copy dir/file from another branch | |
git checkout <branch> -- dirname/file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment