I am using GitHub for the first time and I've spent past few days trying to wrap my head around basic git functionality and commands. Currently, my repository is private–I am the only person using it and pushing commits. However, I want to ensure that I am not creating a tangled web that will cause myself, or others, problems later on if I decide to make it public.
After making my first commit successfully, I realized I had left a proxy API key in my code, so I made an edit (I thought only in my local, but maybe I did in my remote as well) and quickly received a conflict message:
Your branch and 'origin/main' have diverged,
and have 1 and 1 different commits each, respectively
After reading through SO to resolve the conflict, since the changes were insignificant, and I was unable to figure out a better alternative, I decided to use:
git fetch origin
git reset --hard origin/main
After getting my local back up-to-date with main, I still wanted to remove the sensitive information from my commit history entirely. So I once again made local changes to remove the sensitive code & since my repository only contained the initial commit, I staged the initial commit files and tried to amend it: git commit --amend --no-edit
.
However, after running git status
, I again received the same conflict message. At first I thought maybe git always shows a conflict until a commit is pushed and the files become up to date, but I don't believe thats the case, and I'm unsure of what I'm doing wrong.
After going to SO again, I came across multiple posts along the lines of the following: Local branch and remote branch have diverged after amending commit
So, following the post I used: git push --force-with-lease
. This resolved the merge conflict, and correctly amended the changes to the initial commit, but now my repository shows:
"My real name" and "my GitHub username" initial commit "xxxxxx" 2 hours ago
I had changed my user email config using git config --local user.email
(but not my name) after I made the very first initial commit (before resetting). However, I had expected the amended commit to only show the updated author.
Well that did not happen, so I spent more time researching, and per advice on similar questions, used: git commit --amend --no-edit --reset-author
, and once again, now "your branch and main have diverged". I have spent a long while going through tons of posts and articles, and I don't understand why I keep getting this merge conflict error. No one else has edited any files, and after getting my branch up-to-date, I haven't done anything before entering those commands, yet each time, I end up in conflict?