user3845056
user3845056

Reputation: 497

How to force push code from Visual Studio 2019 to GIt

I have created a new Visual Studio 2019 project.

When trying to push it to a Git Repo in Azure Dev Ops I get the below error

Error encountered while pushing branch to the remote repository: rejected Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote changes before pushing again. Failed to push the branch to the remote repository. See the Output window for more details.

How can I resolve this? Is there a way to force the push?

Upvotes: 0

Views: 3868

Answers (1)

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35109

Based on your error message, the remote branch has some changes after your clone the repo in Visual Studio.

To solve this issue, you could try the following two methods:

In Visual studio, when the see the error message, you could see the Pull/Pull and Push option in the pop-ups.

enter image description here

Or in the sync tab

enter image description here

2.Command Line scripts: Since you could run push changes in Visual stduio, the git has been installed already.

cd repo path

git pull

If you couldn't see it, you could run the following commands in cmd:

enter image description here

Update1:

You could run the following git command in your repo file path:

cd repo path

git pull
git add --all
git commit -m "first commit of my code"

git push -f origin master

When you run the git pull, you could check if it returns the message: Already up to date.

If yes, you could run the git push command to directly push the changes to Azure Repo.

Upvotes: 2

Related Questions