2

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.

2
  • "But i want to push changes to my master" Changes are not pushed to local branches. If you are already on master, then git commit will have created a new commit on that branch. There is no need to do anything else. If you are on another branch then you can use git merge to merge your changes into the master branch. I recommend to read git-scm.com/book/en/v2 to learn the basics. Commented Mar 11, 2017 at 5:11
  • @FelixKling i checked, no new commit is created on that branch Commented Mar 11, 2017 at 5:15

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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) 

2 Comments

Thanks for that info. When i entered the command git remote -v i got this: upstream https://github.com/opendatakit/collect.git (fetch) upstream https://github.com/opendatakit/collect.git (push) No mention of origin. Does that means origin is not set?
@Midhun yes, you'd have to add one. git remote add origin <url>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.