最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

bash - git push --all, but follow upstream settings - Stack Overflow

programmeradmin0浏览0评论

when i do

git push --all

i want it to go through my .git/config settings and push all my local branches by following the upstream settings in there! such as

[branch "main"]
  remote = origin
  merge = refs/heads/master

instead, it pushes main as a new undesired branch to origin remote.

(yes, i know, ideally we would abolish all master branches and live happily ever after with only main everywhere, but i did not reach heaven just yet!)

my solution, for now, relies on this script. let's call it gitpushall.sh (which i still haven't even tested):

for branch in $(git for-each-ref --format='%(refname:short)' refs/heads/); do
  upstream="$(git rev-parse --abbrev-ref "$branch"@{upstream} 2>/dev/null || :)"
  [ -z "$upstream" ] && continue
  remote="${upstream%%/*}"
  remotebranch="${upstream#*/}"
  git push "$remote" "$branch:$remotebranch"
done

(because me and my ai could not come up with anything better. also...)

because i have been inactive for so long, i now wonder: do we have a more elegant solution for this?

(you know, other than migrating everyone into fossil or something. i will also happily accept a new paradigm shift in versioning, as i never really liked something about git...)

(too much) more background

too short; didn't understand why?

perhaps i got too frustrated after having to delete my global config setting main branch to upstream to main, which i don't even know why i created (or bothered to look in my own git blame) to begin with, and got blindsided with something obvious.

but yeah, after creating so many scripts to handle committing and deploying to a few different git hosts, and web hosts, and getting most of them working elegantly enough, i feel this stands as the ugliest line out of hundreds of lines of scripts well written! you can check them out on or as you prefer. so, yeah, i will not change everything to freaking master (unless my loving master commands me to) just because 1 "small" project might enforce it.

also, why i prefer to use http instead of https, you might wonder? well, i fear that will get way too off-topic for this question, so i will add more details as comments.

发布评论

评论列表(0)

  1. 暂无评论