0

I made a private github repository in which i cloned a repository I needed to work on. I have all their files locally and already finished coding but I am unable to reflect those changes onto my private github repository.

so this is what i did after cloning the repository

git checkout -b private
git remote add private git@github.com:<github-username>/<repositoryname>.git
git push private -u master

however this would always fail when i tried again it worked but showed this

Enumerating objects: 42, done.
Counting objects: 100% (42/42), done.
Delta compression using up to 8 threads
Compressing objects: 100% (36/36), done.
Writing objects: 100% (42/42), 22.55 KiB | 7.51 MiB/s, done.
Total 42 (delta 15), reused 0 (delta 0)
remote: Resolving deltas: 100% (15/15), done.
remote: 
remote: Create a pull request for 'master' on GitHub by visiting:
remote:      https://github.com/<githubusername>/<repositoryname>/pull/new/master
remote: 
To https://github.com/<githubusername>/<repositoryname>
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'private'.

it was supposed to say private -> master so i know something is not right

What i am trying to do is have a new branch track my changes and have a remote for my private repository so i can push my new branch to the master branch of my repository but i think it is trying to push to the other person's master.

EDIT: when i want to push it tells me to use this first

git push --set-upstream origin private

but when i do that i get denied access by the repository i cloned, this is why i think it is trying to push to their master instead of mine even tho i used my username and repository when setting it up

a-exelle
  • 11
  • 5
  • Note that you created a **remote** and a **branch** both named private. This will likely cause confusion. I suggest that you use different names for branches than for remotes. – Code-Apprentice May 14 '19 at 19:24

4 Answers4

0

You created a branch named private (by running git checkout -b private), but then you've only pushed your master branch (by running git push private master). Remember that the syntax of the push command is:

git push <remote> <refspec>

That first parameter specifies the name of a remote, not the name of a branch.

If you want to push your local branch private to your remote named private, you would write:

git push -u private private

If you want to rename your local private branch to be master on the remote, you would write:

git push -u private private:master
larsks
  • 277,717
  • 41
  • 399
  • 399
  • when i do: git push -u private private i get this error https://github.com/githubusername/repositoryname ! [rejected] private -> private (fetch first) error: failed to push some refs to 'https://github.com/vdorozco/roster' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. – a-exelle May 14 '19 at 17:24
  • It looks like your local repository is not up-to-date with the branch of the same name on the remote. Only you know the proper response to this situation -- do you want to incorporate the remote changes? Or replace the remote `private` branch completely with your local branch? – larsks May 14 '19 at 17:27
  • my repository is just empty and i would like what i have locally to appear in my github repository – a-exelle May 14 '19 at 17:30
  • The error you are seeing suggests that the remote repository is *not* empty. Adding `-f` (for `--force`) to your `git push` invocation will replace the remote `private` branch with your local `private` branch, although that wasn't what you were trying to do in your question (you were trying to push your local `private` branch to the remote `master` branch). – larsks May 14 '19 at 17:41
  • ah i see that is true, i pushed something on but it wasnt my local branch. i would like to replace that with my local branch. – a-exelle May 14 '19 at 17:45
0

Everything I see in the question is Ok. There are no errors, local branch master has been successfully pushed to remote master. Your expectation to see private -> master is wrong: private is the name of the remote, git uses it to get its URL from config. But git pushes branches so it pushes master to master and you see master -> master.

If you have a branch named private you have to push it separately: git push private -u private. If you want the branch private to be pushed to remote master: git push private -u private:master but I recommend to make local and remote branch names to have exactly the same names.

As for the error

! [rejected] private -> private (fetch first)
error: failed to push some refs to 'github.com/vdorozco/roster'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.

see Cannot push to GitHub - keeps saying need merge

You need update your local repository with git pull [--rebase] private master.

https://stackoverflow.com/search?q=%5Bgit%5D+update+were+rejected

phd
  • 82,685
  • 13
  • 120
  • 165
  • both of those push commands give the same error. and when i tried git pull [--rebase] private master, it said this fatal: ']' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. – a-exelle May 14 '19 at 18:09
  • `[]` means an optional flag: a flag that is either used or not. – phd May 14 '19 at 18:14
  • when i run git pull private master it says this: * branch master -> FETCH_HEAD Already up to date. But my files arent on the github repository – a-exelle May 14 '19 at 18:17
0

The given link you comment above doesn't work properly. As you told If you mind to push you local changes to remote simply you can do it from master.

git push origin master

Then if you get a rejected result and not allow to push your code first you have to pull the code from remote master. (This happen because your have remote changes so you have to get them and updated code first). So u should pull the code from master.

git pull origin master

Then you will show some process window over there. close it and push code again.

Case2: If you are in a create a branch you can simply do it by:

git checkout -b <branch name>

Then you working over this branch commit over this branch. Then jump to master again by

git checkout master

If there any commits you want pull from remote master get them by

git pull origin master

Then your local master branch ahead new branch you have already made. So jump to that branch by checkout (like above jumb to master) & rebase with master

git rebase master

Then jump to master and again rebase with branch by

git rebase <branch name>

Then you can simply push your code to remote master

Binoj123
  • 103
  • 1
  • 10
  • when i do git push origin master, i get denied by the user i cloned my repository from. they are my collaborator in my private repository. – a-exelle May 14 '19 at 18:15
  • Do you fork it from another master repo or your repo is the mater repo? – Binoj123 May 15 '19 at 03:56
  • it is from another master repo – a-exelle May 15 '19 at 18:15
  • Ok then, you talking about you fork it from another master and you have your master situation. In that case you should follow above git-rebasing without any conflicts. please go though the below tutorial you can understand it easily how does flow git-rebasing working. https://www.youtube.com/watch?v=f1wnYdLEpgI – Binoj123 May 16 '19 at 03:08
-1

-u is only required when you create a new branch. Otherwise, you should just do git push private master or as a shorthand git push.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • when i do git push private, it says everything is up to date, however my files do not appear on the git hub repository website – a-exelle May 14 '19 at 18:02
  • @a-exelle What is the name of the current branch in your local repo? GitHub only shows the files on `master` by default. You can choose another branch from the the drop down on the left. Alternatively, you can change the default branch for your GitHub repo or push your changes directly to `master`. – Code-Apprentice May 14 '19 at 19:22
  • its called private – a-exelle May 15 '19 at 18:15
  • @a-exelle By default, GitHub will first show the contents of a branch named `master`. You can choose to view a different branch from the drop down near the top of the page. – Code-Apprentice May 15 '19 at 19:12