-3

So I set up a new computer recently (Mac M1), downloaded / setup vscode and am now having trouble with a repo I'm working on.

My goal is just to be able to push to the repository on github when changes are made. However I've been running into a problem where when I try to commit, my terminal outputs that my branch is up to date.

I first realized the problem when I tried to committing a change in the code to the github repo (first running git add . and then running git commit -m "..." . While it had worked previously (such as when initializing the repository), this time there was a message:

On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

The changes however were not on the github repository.

What did I try:

One post mentioned it might be that my "local branch doesn't know about the remote branch" and to run git branch --set-upstream-to origin/master (or in my case git branch --set-upstream-to origin/main). After running that, the output was branch 'main' set up to track 'origin/main'. but when I tried to run git commit -m "..." again I still got the same output as before about my branch being up to date (despite this not being the case).

Another post suggested to try to make a new repo and push the existing code. I tried a few variations of this

  1. Running m -rf .git/ and then initializing the repo in the same folder but pushing to the same 2. Deleting the folder and cloning a new one from github and then making a new commit
  2. Initializing a new github repo and pushing the code. While the first commit worked for each of these ways, following commits returned the same output as the initial problem.

This article suggested to run git remote add origin https://github.com/.../... but resulted in the same output for me after running and trying to commit the changes.

Another article suggested my "local copy... may or may not be up-to-date with your origin remote" and to run git fetch but after running git status again, it outputted that everything was up to date.

Most other articles and posts were some variation of these and the ones that weren't I tried my best to follow but didn't see any changes.

What was I expecting:

I was expecting for there to be changes to commit and that when I pushed, the github repository would reflect those changes.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
asker430
  • 3
  • 1
  • 1
    I suggest you always run `git status` or `git status -uno` before `git commit`, to check which files are to be committed. – ElpieKay Jan 09 '23 at 07:56

2 Answers2

1

In addition of git status, double-check the output of:

git remote -v
git branch -avv
git log --oneline --decorate --graph --all --branches

The last one should show you:

  • where is your local HEAD
  • where is origin/main

You will see what has not yet been pushed, if if those commits are associated to a branhc (or if you are in a detached HEAD mode)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • `git remote -v` outputs: `origin https://github.com/user/repo.git (fetch)` `origin https://github.com/user/repo.git (push)` `git branch -avv` outputs: `* main 6b8d505 [origin/main] testing git again` `remotes/origin/HEAD -> origin/main` `remotes/origin/main 6b8d505 testing git again` `git log --oneline --decorate --graph --all --branches` outputs: `* 6b8d505 (HEAD -> main, origin/main, origin/HEAD) testing git again` `* 4b13fd5 trying to fix git issues` – asker430 Jan 09 '23 at 08:14
  • @asker430`HEAD -> main` is at main: everything has been pushed – VonC Jan 09 '23 at 08:17
  • while it might look like that, even if I make a change and try to commit, it outputs that there is nothing to commit and the github repo doesn't update – asker430 Jan 09 '23 at 08:20
  • @asker430 committing alone is not enough and remain in your local repository. You need `git push` to publish it. – VonC Jan 09 '23 at 08:22
  • Yeah I've run `git push`, `git push origin main` and other variations. I think it might be a problem with github signin or authentication. I signed out and back in and the first commit and push worked but the following ones didn't (this was also the case for initting branches - the init and first commit and push worked but following ones didn't) – asker430 Jan 09 '23 at 08:36
  • @asker430 What do you get on a `git push`? – VonC Jan 09 '23 at 08:46
0

The solution was very silly.

I had just downloaded vscode to my new computer and never turned autosave on. Because of this, git wasn't aware of the changes I was making and so it outputted that my branch was up to date (when the text editor seemed to show otherwise).

asker430
  • 3
  • 1