Oleg
Oleg

Reputation: 661

Error in git: You can only push your own commits in this repository

Yesterday I started to recieve errors when trying to push my commit to repo, how to fix it? And I am not admin of this repo.

remote: You can only push your own commits in this repository
remote: Commit commitName was committed by <myName> <[email protected]>
To ssh://bitbucket.awg.ru/repo
 ! [remote rejected] branchName -> branchName (pre-receive hook declined)
error: failed to push some refs to 'ssh://[email protected]/repo'

Update

Thanks everybody, the problem is solved. The problem was on the Bitbucket side, the admininstrator changed some options. Now everything is OK.

Upvotes: 31

Views: 72982

Answers (8)

Gv Ravi
Gv Ravi

Reputation: 391

Sometimes setting user.email with git command may not set the updated email.

In my case(Windows), I see a .gitconfig file under C:/Users/Mine/.gitconfig.

I edited this file with my desired email and the username.

[user]
name = YourUsername
email = YourEmailId

Done push successfully.

Upvotes: 0

mahesh nanayakkara
mahesh nanayakkara

Reputation: 616

If the issue keep persist even after you set user.email and user.name? You may need change your commit author log to match with this user. Just check the git log before run below cmd.

git commit --amend --reset-author --no-edit

Upvotes: 14

Roger Perez
Roger Perez

Reputation: 3129

You have to undo the commit that has the incorrect email address, then update the git config as mentioned below. If you committed multiple times you may need to cherry-pick and then commit but only after running through these steps:

# remove "--global" if you only want to update it for the local repo
git config --global user.email "Your Email"
git config --global user.name "Your Name"

Make the new commit and then you should be able to push.

Upvotes: 0

Oleg
Oleg

Reputation: 661

Thanks everybody, problem is solved. Problem was on Bitbucket side, administrator changed some options. Now everything is OK.

UPDATE

As per @Oleg who asked the question. The problem in general happens because of a Bitbucket hook. This hook will reject any push that contains a commit not committed by the user who pushes to the server.

To solve the issue:

  • You must have Admin access to the repository in Bitbucket server
  • Go to the repository in the server
  • Then ⚙ Repository settings in the sidebar
  • Select Hooks
  • Disable Verify Committer hook
  • You are done

Upvotes: 25

Asanka Siriwardena
Asanka Siriwardena

Reputation: 961

I had the same issue while working with different projects in my office machine. Git is configured global with my office email '[email protected]'. The other is an open source project of GitLab repository, authenticated by my gmail account.

Push for the GitLab repository did not work, showing the same error as above. The reason was, the Author of the commit message was originated from my office email.

Keeping a different committer name and email per Repository, worked for me. I have modified the user.email for the GitLab repository. This is simply omitting the --global flag. enter image description here

Now all of your commits will be originated from the new Author you set for the repository preventing the above error.

Upvotes: 1

Neupane
Neupane

Reputation: 46

  1. Go to your repo browser and check what your username and email is on your profile ( the top right corner)

  2. In git bash update your detail as per your git web profile git config --global user.email "[email protected]" git config --global user.name "USERNAME"

  3. You will need to undo the commit and then redo it after you changes you user detail in step 2

  4. Push the changes git push

Upvotes: 2

eeijlar
eeijlar

Reputation: 1342

Assuming you have already done git config as per @Manish R answer, then check that Bitbucket hasn't enforced the Verify Committer hook. See Project -> Settings -> Hooks

enter image description here

Upvotes: 1

Manish R
Manish R

Reputation: 2372

You will need to set your identify before pushing it to bitbucket

git config --global user.email "Your Email"
git config --global user.name "Your Name"
git push origin <branch-name>

Upvotes: 18

Related Questions