Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine push alias to get confirmation if more than 4 commits pushed #170

Open
gberche-orange opened this issue Dec 17, 2024 · 0 comments
Open

Comments

@gberche-orange
Copy link
Member

Expected behavior

As an operator,
In order to prevent pushing by mistake a featre branch with many commits (typically created from another release),
I need the git push alias to get confirmation when number of commits to be pushed exceed 5

#See https://stackoverflow.com/a/61395451/1484823
NB_COMMITS_TO_PUSH=$(git rev-list origin/main.. --count)
if [[ ${NB_COMMITS_TO_PUSH} -gt 5 ]]; then
   echo "Are you sure to push ${NB_COMMITS_TO_PUSH} commits to branch origin/main? Is you branch based on the right source branch ?"
....
fi

See also related git commands to list commits yet to be pushed https://stackoverflow.com/questions/2016901/how-to-list-unpushed-git-commits-local-but-not-on-origin/2016954#2016954

Observed behavior

alias push
alias push='git pull --rebase ; git fetch --prune ; git push'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant