Skip to content

Instantly share code, notes, and snippets.

@wwerner
Created March 26, 2020 10:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wwerner/48a7771aca8631aebedae0323ed5dd66 to your computer and use it in GitHub Desktop.
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
# 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