I use the following commands to push local branch changes to remote branch (in some automated script):
#while being on main branch
git checkout -B new_local_branch_unix_timestamp
#optionally modify some files
# check if there are modified files
git diff --exit-code
# if there are changes commit and push
git commit -am 'commit message'
git push --set-upstream origin new_local_branch_unix_timestamp
# get latest local commit id
git rev-parse HEAD
# busy wait until latest remote commit id equal to latest local commit id
# latest remote commit id is extracted using
git rev-parse origin/new_local_branch_unix_timestamp
Busy wait means applying git rev-parse origin/new_local_branch_unix_timestamp
fixed number of times until local last commit id equals remote last commit id.
Running git rev-parse origin/new_local_branch_unix_timestamp
to get latest remote commit id occasionally returns below output and error.
stdout: origin/new_local_branch
sterr: fatal: ambiguous argument 'origin/new_local_branch_unix_timestamp': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]'
It's very rare and random.
I always mitigate it by removing local repository, recloning remote one. Then the above steps succeed until the next time.
Is there a reason why it happens and is there a better way to mitigate it?
There could be many remote branches created earlier with similar names (having similar first characters, because of unix timestamps similarity).
Could this be the reason for sterr: fatal: ambiguous argument
git error?