Skip to content

Instantly share code, notes, and snippets.

@salhernandez
Created April 27, 2023 23:21
Show Gist options
  • Save salhernandez/eee4f49abb8786564b2eb8daa83b24cc to your computer and use it in GitHub Desktop.
Save salhernandez/eee4f49abb8786564b2eb8daa83b24cc to your computer and use it in GitHub Desktop.
#!/bin/bash
function get_branch() {
git branch --no-color | grep -E '^\*' | awk '{print $2}' \
|| echo “default_value”
}
branch_to_merge="master"
current_branch=$(get_branch)
timestamp=$(date +%m-%d-%Y_%H-%M-%S)
stash_mame="${current_branch}_${timestamp}"
# stash changes
echo $stash_mame
echo -e "===creating ${stash_name} stash==="
git stash push -m "${stash_name}"
# update branch to merge from remote
echo -e "\n\n===updating ${branch_to_merge} branch"
git fetch origin $branch_to_merge:$branch_to_merge
# merge onto current branch
echo -e "\n\n===merge ${branch_to_merge} branch to ${current_branch}==="
git merge $branch_to_merge
# apply stash
echo -e "\n\n==applying ${stash_name}==="
# git stash apply $(git stash list | grep "${stash_name}" | cut -d: -f1)
echo -e "\n\n\n"
read -p "Press enter to continue"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment