Burak
Burak

Reputation: 5764

How can I clear remote repository in git?

I want to clear the remote repository and push the new files.

I' am getting

git commit -m "fix"
# HEAD detached from 0027561
nothing to commit, working directory clean

and nothing is pushed to the remote.

I tried to git init, but it didn't work.

How can I do that?

Upvotes: 0

Views: 334

Answers (2)

Jilles van Gurp
Jilles van Gurp

Reputation: 8274

Clearing the repository (remote or local) is not something you can actually do in git. Not sure why you would want that. Git init creates a new repository locally. It will fail if you run it on an existing repository.

The error you are getting is about your local HEAD being detached, meaning you are not actually on a branch, probably due to stuff that you did earlier that you declined to mention in your question. If you do a git status it will tell you this.

Fix that by checking out a branch: git checkout master should work on most repositories that have a master branch. That gets you back on the master branch.

Commit doesn't actually push to remote. So even if you were not detached that still wouldn't send your commit remotely but it would simply create the commit in your local git repository, which lives in your .git directory.

Once you have an actual branch with an actual commit you can try pushing to the remote repository. I assume you actually have one and that you actually cloned it at some point. If you did, it is typically called 'origin' and you need to push the commits from your local master branch to the master branch in origin.

git push typically does that job. If that fails, a git push --all (all branches) or a git push origin master (just the master branch).

Upvotes: 0

VonC
VonC

Reputation: 1323115

You can make a new branch

git checkout -b newBranch
git push -u origin newBranch

If you want to update an existing branch like master, you can rebase that new branch on top of master:

git rebase master
git checkout master
git merge newBranch
git push heroku master

I prefer that to directly checkout master, or to force master to the new branch (git branch -f master newBranch), because it takes into account the case where new commits were done on master concurrently (meaning "while commits where done with the detached HEAD")

Upvotes: 2

Related Questions