'VS Code Showing Publish Branch Button When Branch Was Already Pushed

I used VS Code terminal to create a new branch, and then pushed the commit to GitLab. I've confirmed on my GitLab account that the branch was successfully pushed but VS Code is still showing a Publish Branch button. When I execute git status in the terminal, i receive the response: nothing to commit, working tree clean.

I've tried restarting VS Code and running git fetch but the Publish Branch button is still showing. I have not yet clicked on the Publish Branch button because I don't know what it will do and I've already sent a merge request for this branch. Does anyone have any recommendation on how I should go about resolving this minor but annoying issue?



Solution 1:[1]

I believe the issue is that you don't have upstream tracking set up, because I ran into the same issue and just fixed it about 5 minutes ago. So first of all, to fix your existing issue, I believe all you need to do is this.

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

This just sets up upstream tracking for your branch, which should fix your existing problem.

The rest of this post is just quickly walking through the whole process from creating a new branch to pushing it. So first, switch to the correct branch.

git checkout branchname.

If you haven't created the branch yet, you would instead do git checkout -b branchname to create the new branch.

Then make whatever changes you're going to make, and then add the changed files to the staging area.

git add .

And then commit the changes

git commit -m "commit message"

And then (and I believe this is where you ran into the issue), when you're ready to push your changes, you need to run this:

git push -u origin branchname

I think that you just forgot the -u, which is an option that sets up upstream tracking for your branch. Once I did that, the "Publish Branch" button went away. I know this was asked a month ago so you probably figured it out quite a while ago, but hopefully this will help someone in the future.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 monster319