1

Can someone help me with below issue:
I cloned data from my professor Git url and trying to set my private account has upstream master and push the code in my private repository (https://github.com/accountid/reponame').

When I git checkout -b branchname, it is creating a new branch in my professors repo not in my account I want to create a master in my private repo.

But I am getting the below error:

 [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/accountid/reponame'
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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

How can I push to my private repository?

aynber
  • 22,380
  • 8
  • 50
  • 63
vss2020
  • 11
  • 1

2 Answers2

1

You just need to read the error message.

You cannot push (unless using the force -f) to the remote repository if your local branch does not have the latest message.

Read the error and you will see that you need to perform pull before your push.

# pull changes from the server
git pull

# If you have conflicts resolve them and if not simply push to the server
# Assuming your remote is the  origin
git push origin <branch>  

When I git checkout -b branchname, it is creating a new branch in my professors repo not in my account I want to create a master in my private repo.

If the repository is not under your account and you are not contributor, you need to fork it first.

enter image description here enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
-1

First, check what origin points to:

cd /path/to/repo
git remote -v

If origin still refers to your professor git url, then a push won't work, since you don't have the right to push to that repository (only clone/pull/fetch).

You should do:

git remote rename origin upstream
git remote add origin https://github.com/accountid/reponame

Second, check if you have a credential helper that could cache your HTTPS username/password credentials:

git config credential.helper
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250