0
cat .git/FETCH_HEAD points to branch branch_a
cat .git/HEAD points to ref: refs/heads/branch_temp

When i perform a git push it prompts me the following:

git push
fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use
 
git push origin HEAD:branch_a

To push to the branch of the same name on the remote, use

    git push origin HEAD

I have used git push origin HEAD for now.

I would like to set the HEAD and FETCH_HEAD to point to branch_temp -> HEAD Secondly, does this always occur when you copy/checkout a branch?

Ajith Moni
  • 1
  • 1
  • 2
  • 2
    Why do you care what `FETCH_HEAD` points to? That's telling you the latest remote commit fetched from `branch_a`, while you're working on an entirely different branch. If you want to update `origin/branch_a`, you should be working on `branch_a`, rather than `branch_temp`. – Useless Jul 22 '22 at 10:53
  • In fact, if you just push `branch_temp` and then fetch again, `FETCH_HEAD` will contain the head refs for _both_ branches, while `HEAD` will only ever have your current working tree HEAD. What are you actually trying to achieve? – Useless Jul 22 '22 at 10:55
  • I figured it out. We need to set the upstream (git --set-upstream-to) to point to it. ``` git branch --set-upstream-to origin/branch_temp' branch 'branch_a' set up to track 'origin/branch_temp'. ``` Now when i do push and pull, I'm sure it's going into the right branch. – Ajith Moni Jul 22 '22 at 10:57
  • Figured what out? Do you still have a question? – Useless Jul 22 '22 at 10:58
  • I believe when i checked out the branch from **branch_a** to **branch_temp**, the `FETCH_HEAD` was still pointing to **branch_a** where as `HEAD` was pointing to **branch_temp**. There was always this scare where I might commit into branch_a by mistake. – Ajith Moni Jul 22 '22 at 11:05
  • @Useless I am in branch_temp working on branch_temp. I do not want to merge or need to work with branch_a but only into branch_temp. – Ajith Moni Jul 22 '22 at 11:18

1 Answers1

0

The following command solved the issue.

git branch --set-upstream-to origin/branch_temp 

git push and git pull do not show any messages.

cat .git/FETCH_HEAD and cat .git/HEAD both point to the same branch

The detailed answer lies in here. Please feel to add or correct my understanding.

Ajith Moni
  • 1
  • 1
  • 2
  • You can also just `git push --set-upstream` on the first push (assuming you already set the push default to current) – Useless Jul 22 '22 at 12:20