'Could not read from remote repository, in other words push rejectec

I'm trying to push my branch, made the necessary changes and made the commit. However once I press push on Android Studio, it tells me that Push is rejected and it's 100% done checking and testing. For what I see it has something to do with the remote origin of the branch. So I don't know much about Git and it's remote origin issues, so I presume that once I checked out on "developer" branch it's fine, created a branch on "developer" and clearly it won't let me push. Everything is connected and the remote origin is on it's right place. Here is what I have done and what I've got so far.

In Terminal:

PS E:\Projects\GitHub\Rijs-museum\RijsMuseum> git remote add origin https://github.com/XCMachine/Rijs-museum.git
error: remote origin already exists.
PS E:\Projects\GitHub\Rijs-museum\RijsMuseum> git push feature/description_parameter_change
fatal: 'feature/description_parameter_change' does not appear to be a git repository
fatal: Could not read from remote repository.

In Console:

23:05:49.686: [..\..\Rijs-museum] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/feature/description_parameter_change:feature/description_parameter_change --set-upstream
Enumerating objects: 50, done.
Counting objects:   2% (1/50)
Counting objects:   4% (2/50)
Counting objects:   6% (3/50)
Counting objects:   8% (4/50)
Counting objects:  10% (5/50)
Counting objects:  12% (6/50)
Counting objects:  14% (7/50)
Counting objects:  16% (8/50)
Counting objects:  18% (9/50)
Counting objects:  20% (10/50)
Counting objects:  22% (11/50)
Counting objects:  24% (12/50)
Counting objects:  26% (13/50)
Counting objects:  28% (14/50)
Counting objects:  30% (15/50)
Counting objects:  32% (16/50)
Counting objects:  34% (17/50)
Counting objects:  36% (18/50)
Counting objects:  38% (19/50)
Counting objects:  40% (20/50)
Counting objects:  42% (21/50)
Counting objects:  44% (22/50)
Counting objects:  46% (23/50)
Counting objects:  48% (24/50)
Counting objects:  50% (25/50)
Counting objects:  52% (26/50)
Counting objects:  54% (27/50)
Counting objects:  56% (28/50)
Counting objects:  58% (29/50)
Counting objects:  60% (30/50)
Counting objects:  62% (31/50)
Counting objects:  64% (32/50)
Counting objects:  66% (33/50)
Counting objects:  68% (34/50)
Counting objects:  70% (35/50)
Counting objects:  72% (36/50)
Counting objects:  74% (37/50)
Counting objects:  76% (38/50)
Counting objects:  78% (39/50)
Counting objects:  80% (40/50)
Counting objects:  82% (41/50)
Counting objects:  84% (42/50)
Counting objects:  86% (43/50)
Counting objects:  88% (44/50)
Counting objects:  90% (45/50)
Counting objects:  92% (46/50)
Counting objects:  94% (47/50)
Counting objects:  96% (48/50)
Counting objects:  98% (49/50)
Counting objects: 100% (50/50)
Counting objects: 100% (50/50), done.
Delta compression using up to 12 threads
Compressing objects:   5% (1/19)
Compressing objects:  10% (2/19)
Compressing objects:  15% (3/19)
Compressing objects:  21% (4/19)
Compressing objects:  26% (5/19)
Compressing objects:  31% (6/19)
Compressing objects:  36% (7/19)
Compressing objects:  42% (8/19)
Compressing objects:  47% (9/19)
Compressing objects:  52% (10/19)
Compressing objects:  57% (11/19)
Compressing objects:  63% (12/19)
Compressing objects:  68% (13/19)
Compressing objects:  73% (14/19)
Compressing objects:  78% (15/19)
Compressing objects:  84% (16/19)
Compressing objects:  89% (17/19)
Compressing objects:  94% (18/19)
Compressing objects: 100% (19/19)
Compressing objects: 100% (19/19), done.
Writing objects:   3% (1/27)
Writing objects:   7% (2/27)
Writing objects:  11% (3/27)
Writing objects:  14% (4/27)
Writing objects:  18% (5/27)
Writing objects:  22% (6/27)
Writing objects:  25% (7/27)
Writing objects:  29% (8/27)
Writing objects:  33% (9/27)
Writing objects:  37% (10/27)
Writing objects:  40% (11/27)
Writing objects:  44% (12/27)
Writing objects:  48% (13/27)
Writing objects:  51% (14/27)
Writing objects:  55% (15/27)
Writing objects:  59% (16/27)
Writing objects:  62% (17/27)
Writing objects:  66% (18/27)
Writing objects:  70% (19/27)
Writing objects:  74% (20/27)
Writing objects:  77% (21/27)
Writing objects:  81% (22/27)
Writing objects:  85% (23/27)
Writing objects:  88% (24/27)
Writing objects:  92% (25/27)
Writing objects:  96% (26/27)
Writing objects: 100% (27/27)
Writing objects: 100% (27/27), 2.10 KiB | 537.00 KiB/s, done.
Total 27 (delta 9), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas:   0% (0/9)        
remote: Resolving deltas:  11% (1/9)        
remote: Resolving deltas:  22% (2/9)        
remote: Resolving deltas:  33% (3/9)        
remote: Resolving deltas:  44% (4/9)        
remote: Resolving deltas:  55% (5/9)        
remote: Resolving deltas:  66% (6/9)        
remote: Resolving deltas:  77% (7/9)        
remote: Resolving deltas:  88% (8/9)        
remote: Resolving deltas: 100% (9/9)        
remote: Resolving deltas: 100% (9/9), completed with 9 local objects.        
error: failed to push some refs to 'https://github.com/XCMachine/Rijs-museum.git'
To https://github.com/XCMachine/Rijs-museum.git
!   refs/heads/feature/description_parameter_change:refs/heads/feature/description_parameter_change [remote rejected] (cannot lock ref 'refs/heads/feature/description_parameter_change': 'refs/heads/feature' exists; cannot create 'refs/heads/feature/description_parameter_change')
Done


Solution 1:[1]

The ultimate error is simple enough, but let's go through each error one at a time.

The first error

When you ran this:

git remote add origin https://github.com/XCMachine/Rijs-museum.git

you got an error message:

error: remote origin already exists.

The result of the error is that origin, which already exists, did not change. Fortunately, it seems that the current setting of origin is already https://github.com/XCMachine/Rijs-museum.git. I base this on your Console output, which has this near the end:

error: failed to push some refs to
'https://github.com/XCMachine/Rijs-museum.git'

The second error

git push feature/description_parameter_change

This command is missing a word. The first word, git, is the name of the overall command to run. The second word, push, is the Git sub-command to run—the verb for Git. The third word, which should have been origin, is the name of the repository to which you want to do your git push. Since the third word here is feature/description_parameter_change, your Git assumed this was the name of a repository. But your Git software was unable to find a repository under that name. (It never tried it as a branch name because the thing that goes in the third-word slot is never a branch name.)

(You wanted:

git push origin feature/description_parameter_change

here. However, that would just get you the last error.)

The last error

Finally, the Android Studio push itself invoked git push correctly. This sent your new commits (and any files and other supporting objects required) to GitHub. But then you hit this problem:

'refs/heads/feature' exists; cannot create
'refs/heads/feature/description_parameter_change'

The refs/heads/ part here is a prefix that means the rest of this name is a branch name. (Git typically suppresses this extra stuff for humans, but Android Studio uses the full names everywhere, and you should know about this anyway because Git itself is not entirely consistent about when it human-izes output, and when it doesn't.)

So, GitHub are telling you: I have a branch named feature. You are now asking me to create a new branch named feature/description_parameter_change. I can't do that. The problem here is that Git sometimes1 stores branch names via OS-level folder-and-file-names. If you make a file named feature you cannot make a folder named feature too, which means you can't store feature/description_parameter_change. Since Git might use OS-level names for these, Git stops you from creating such a branch name.

You have two options:

  • have GitHub rename their branch feature, or
  • use a GitHub-side branch name other than feature/description_parameter_change.

You can do the former by using the GitHub web interface to rename your GitHub branch, for instance. You can do the latter locally with git branch -m, e.g.:

git branch -m feature/description_parameter_change feat-d-p-c

followed by:

git push origin feat-d-p-c

(note: four words: command git, verb push, repository name origin, branch name) so that your local Git, with its (local) branch name, is using a name other than feature/description_parameter_change, and then Git's default, which is to ask GitHub to create a branch with the same name, will be asking for GitHub to create feat-d-p-c which doesn't look like a folder named feature containing a file.


1Long ago, Git always did this. Then that became inefficient, and now Git sometimes does this, but just in case, it makes sure that it is always possible. In future Git versions, Git may never or hardly ever do this, but for backwards compatibility, the restriction is likely to remain in place forever.

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 torek