Last active
March 27, 2018 13:22
-
-
Save Artistan/c469456ea65bc6f056b2a307bddc8b77 to your computer and use it in GitHub Desktop.
Git Checkout, Merge and Squish
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/bash | |
master="master" | |
# git-branch.sh dev | |
branch="$1" | |
git checkout $master | |
git fetch --all | |
git pull upstream $master | |
git status # check that everything is clean... | |
git checkout -b $branch |
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/bash | |
# the number is the count of commits that you have after creating your dev branch -1 (8 commits -1 = 7) | |
# this will squish all the commits into the first one you made after branching | |
# git-squish.sh dev 12 | |
branch="$1" | |
revisions="$2" | |
# squish all your commits BACK into the first one of the current branch. | |
./git-squish.sh $branch $revisions | |
# merge your one commit into | |
./git-merge.sh $branch |
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/bash | |
master="master" | |
# merge all your commits BACK into the first one of the current branch. | |
# git-merge.sh dev | |
branch="$1" | |
# Reset the current branch to the commit just before the last 12: | |
git checkout $branch | |
# git rebase onto $master via phpstorm | |
# git push origin $branch | |
# create pull request |
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/bash | |
# git-squish.sh dev 12 | |
branch="$1" | |
revisions="$2" | |
# Reset the current branch to the commit just before the last 12: | |
git checkout $branch | |
git reset --hard HEAD~$revisions | |
# HEAD@{1} is where the branch was just before the previous command. | |
# This command sets the state of the index to be as it would just | |
# after a merge from that commit: | |
git merge --squash HEAD@{1} | |
# Commit those squashed changes. The commit message will be helpfully | |
# prepopulated with the commit messages of all the squashed commits: | |
git commit |
Other interesting links about git...
http://fle.github.io/git-tip-keep-your-branch-clean-with-fixup-and-autosquash.html
https://github.com/servo/servo/wiki/Github-workflow
another good one
https://gist.github.com/meagar/ae2c7f1b200d7fa52508
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/a/5190323/372215