Created
March 26, 2020 10:46
-
-
Save wwerner/48a7771aca8631aebedae0323ed5dd66 to your computer and use it in GitHub Desktop.
[git] stash local changes to new branch and reset the current one to its origin
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
# git safe origin | |
# - | |
# save local work to a separate branch and revert to the current branches origin | |
# I have this in my ~/.zshrc | |
gso() | |
{ | |
branch=$(git rev-parse --abbrev-ref HEAD); qualifier=$(date -u +"%Y-%m-%dT%H%M%S") \ | |
&& git add . \ | |
&& git commit -m "Saving local work from $branch to local/stash/$branch-$qualifier" \ | |
&& git branch local/stash/$branch-$qualifier \ | |
&& git checkout $branch \ | |
&& git fetch origin \ | |
&& git reset --hard origin/$branch | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment