Prithviraj Mitra
Prithviraj Mitra

Reputation: 11812

Git push force to update a branch

I have a project directory(without git folder) where I am working and trying to update an existing remote branch forcefully.

Steps I have taken -

1. git init
2. git add .
3. git commit "Fresh update after changing db"
4. git remote add origin <repo_url>
5. git push origin staging

And I get the below error -

error: src refspec staging does not match any.
error: failed to push some refs to '<repo_url>'

When I do git branch -a it doesn't show all the branches just only master.

Any help is highly appreciated.

Upvotes: 0

Views: 2324

Answers (2)

Paritosh Singh
Paritosh Singh

Reputation: 6384

Take pull after adding remote:

1. git init
2. git add .
3. git commit "Fresh update after changing db"
4. git remote add origin <repo_url>
5. git checkout -b staging
6. git fetch
7. git push -f origin staging

Avoid using force push if possible. Let me know exact scenario for better solution.

Upvotes: 3

masseyb
masseyb

Reputation: 4132

You're on the master branch and trying to push to the remote staging branch. You should git checkout -b staging locally before committing and pushing the changes:

git init
git add .
git checkout -b staging
git commit "Fresh update after changing db"
git remote add origin <repo_url>
git push origin staging

Upvotes: 1

Related Questions