New to coding so i've been trying to find my way around git. Every time I seem to want to push a commit from my terminal it seems to automatically push to the master branch rather than the main. Now I know that I can just change the branch in Github to make master the main one i'm just curious as to why this is happening. I tried "git fetch" "git reset --hard origin/master" as well as trying to rename the branch to no avail, even switching branch like I said before it would push to the main branch on it's own. Here is a run down of how I go about it maybe i'm doing something wrong, first "git init", then "Git add .", then "git commit -m "message", then "git remote add origin master" then I push. Everything goes through fine except on github i'm now asked if I want to pull the commit and there are no changes to see. I included pictures with an example because i'm not sure i'm explaining everything properly. As I said tried to figure this one out on my own but i'm most likely not really understanding the origin of the problem
thanks for any pointer or tips you could provide to fix this.
//Update So I updated my git and I now get a new error that I don't understand : enter image description here trying git force enter image description here
Found the solution to my problem thank you everyone
CodePudding user response:
If git init
puts you on the unborn master
branch instead of main
, and you wish it were main
, you have many options:
Update your Git. Newer Git versions default to
main
.Or else, change your
init.defaultBranch
config.git config --global init.defaultBranch main
Or, just say
git init -b main
instead.Or, after
git init
, saygit branch -M main
.