Skip to content

Commit

Permalink
git-checkoutdefault: auto-fetch the remote's HEAD if not already set
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackenmen committed Apr 8, 2023
1 parent f54e4d9 commit f73f7dd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion bin/git-checkoutdefault
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
if ! default_branch=$(git rev-parse --abbrev-ref origin/HEAD 2>/dev/null); then
echo 'origin/HEAD not set, querying the remote to determine its default branch...'
git remote set-head origin -a
if ! default_branch=$(git rev-parse --abbrev-ref origin/HEAD); then
exit 1
fi
fi
default_branch="${default_branch#origin/}"
git checkout "$default_branch" || exit 1

0 comments on commit f73f7dd

Please sign in to comment.