Midhun
Midhun

Reputation: 744

Unable to push commits to git

I' am new to git. I' am contributing to an open source project which is in the git. I forked it and created a branch. Its an android project. Then i cloned it to create a local copy and saved it in a folder. I opened it in the android studio, made the required changes.Then i did the following:

git add <the file name where i made changes>

git commit -m <message>

At this point i' am still confused as to where are the changes committed? I assume its in the local copy thats saved in my computer. Then i try to push it and it gives me the error:

git push upstream master
Username for 'https://github.com': Midhun07
Password for 'https://[email protected]': 
remote: Permission to opendatakit/collect.git denied to Midhun07.
fatal: unable to access 'https://github.com/opendatakit/collect.git/': The requested URL returned error: 403

But here opendatakit/collect.git is where the git is trying to push the changes. But i want to push changes to my master rather than the upstream/master. But when i tried to do git push master it gives me following error.

fatal: 'master' does not appear to be a git repository
fatal: Could not read from remote repository.

I also one another problem of my master branch being behind by 9 commits as compared to upstream/master. I' am all confused. please guide me.

Upvotes: 2

Views: 16294

Answers (2)

Dan Lowe
Dan Lowe

Reputation: 56667

The typical scenario on Github goes like this.

  1. You find a public repository, e.g. github.com/opendatakit/collect
  2. You fork a copy. Now you have your own copy, e.g. github.com/Midhun07/collect
  3. You clone it to your computer to work. By default, git will name the remote for your repository origin.
  4. A common practice is to add a second remote for the project you forked from, and name it upstream.

That's what I'm guessing you have done here (especially since you seem to have done exactly that, when I looked on Github).

You do not have privileges to write to opendatakit's copy on Github. That's why you forked your own copy in the first place.

What you need to do is push to your forked copy, not to theirs.

git push origin master

You can see what different remotes you have, and what URLs they will try to push to, using the remote command.

git remote -v

It probably looks like this.

origin  [email protected]:Midhun07/collect.git (fetch)
origin  [email protected]:Midhun07/collect.git (push)
upstream    https://github.com/opendatakit/collect.git (fetch)
upstream    https://github.com/opendatakit/collect.git (push)

Upvotes: 0

janos
janos

Reputation: 124774

upstream is the original project you forked from, https://github.com/opendatakit/collect. Only the maintainers of the project can push to that.

If you want to push your local changes to GitHub, then push to your fork, https://github.com/Midhun07/collect. It should be called origin, not upstream. So change your command to:

git push origin master

At this point I am still confused as to where are the changes committed?

To your local Git repository. If this point is not clear to you then you need to learn a bit more Git.

I also one another problem of my master branch being behind by 9 commits as compared to upstream/master. I' am all confused. please guide me.

This means that the original project has evolved: others have added 9 commits since the last time you synchronized with it (forked from). If you want to get those commits in your local clone, you can rebase:

git fetch upstream master
git rebase upstream/master

Be careful, there might be conflicts. You can read more about rebasing and resolving conflicts in the Git book.

Upvotes: 4

Related Questions