The name of the default branch is configurable with git-config, the default changed to "main" a while ago. You don't have to explicitly create that branch, the first commit goes there by default.
Like you've discovered, if there is nothing committed then you really don't have a branch yet (it would not make sense to have a branch with no content).
There are things that git configures per user and others that it configures per repo or both. That isn't completely obvious unless you know to look for it, though it does make sense once you know.
Since you are new to git, I'll just say that the free book is worth every second you spend with it. For my own use, the following tasks/topics have been very helpful:
- amending the last commit (message or otherwise)
- creating/using branches
- understanding "remotes" and how/when to push local branches
- the difference between "merge" and "rebase"
- git diff
- git status
- git is neither GitHub nor GitLab
- git restore <- this is your friend
I offer that list because it seems to cover the things that the people I help with git usually run into first. Otherwise, it depends on what you're doing, but if you conceive of a question that you want to ask about your code history, git can likely answer it.
--
Stephen L. Ulmer
Enterprise Architect
Mainline Information Systems
(m) 352-870-8649
Original Message:
Sent: 8/19/2022 9:06:00 AM
From: Steve Munday
Subject: RE: AIX 7.3 - git 2.35.1 -- git branch & git switch not working
** Update **
Even though git status said I was in the "main" branch it wasn't until I'd committed a file to "main" that it appeared in the output of git branch. All looking much better now.
------------------------------
Steve Munday
AIX, IBM i, HMC, PowerVM
------------------------------
Original Message:
Sent: Thu August 18, 2022 09:20 AM
From: Steve Munday
Subject: AIX 7.3 - git 2.35.1 -- git branch & git switch not working
Ah! Ok, so even though my initial git status says that I'm "On branch main" I have to create that branch too, I thought the "git init" would have done that itself, I guess not,. This would explain why it errored out referencing main.
When in the "develop" branch I did do a commit and now see "develop" when running the "git branch" command.
Many thanks, Steve
------------------------------
Steve Munday
AIX, IBM i, HMC, PowerVM
Original Message:
Sent: Thu August 18, 2022 08:50 AM
From: C- -T
Subject: AIX 7.3 - git 2.35.1 -- git branch & git switch not working
not clear why you are expecting the "main" branch to exist per default. beside this, you need at least one commit do see the standard branch, which is NOT necessarly named "master" since 2020.
guess you need to read the git manual.
------------------------------
I regret starting this entire conversation
Original Message:
Sent: Thu August 18, 2022 08:32 AM
From: Steve Munday
Subject: AIX 7.3 - git 2.35.1 -- git branch & git switch not working
Good day,
I've installed git on our AIX 7.3 LPAR to manage our Bash scripts (amongst other things). I successfully created a git repo within a demo directory structure however I'm finding that certain sub-commands either return nothing or error out, details below:
# whoamiroot# echo $PATH/opt/freeware/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java8_64/jre/bin:/usr/java8_64/bin:/usr/local/bin# oslevel -s7300-00-02-2220# rpm -qa | grep gitgit-core-2.35.1-1.ppcgit-2.35.1-1.ppcgit-core-doc-2.35.1-1.noarch## git initInitialized empty Git repository in /home/mundays/scripts/.git/# git statusOn branch mainNo commits yetUntracked files: (use "git add <file>..." to include in what will be committed) curl_logonv8.xml curl_logonv9.xml demo.sh demo1.sh lpargrouplist.xml lparlist.xmlnothing added to commit but untracked files present (use "git add" to track)#### git branch fails to list "main" branch## git branch --list#### git branch <new-branch> errors out## git branch developfatal: not a valid object name: 'main'# git switch -c developSwitched to a new branch 'develop'# git statusOn branch developNo commits yetUntracked files: (use "git add <file>..." to include in what will be committed) curl_logonv8.xml curl_logonv9.xml demo.sh demo1.sh lpargrouplist.xml lparlist.xmlnothing added to commit but untracked files present (use "git add" to track)#### git branch fails to list "main" and "develop" branches## git branch --list#### git switch back to "main" errors out## git switch mainfatal: invalid reference: main#
Clearly something is amiss however I'm not sure what that might be and/or where to look to fix it.
Any advice/guidance would be very welcome.
Many thanks, Steve
------------------------------
Steve Munday
AIX, IBM i, HMC, PowerVM
------------------------------