I’m trying to push one of my projects to github, and I keep getting this error:
peeplesoft@jane3:~/846156 (master) $ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
So I tried it and got this:
peeplesoft@jane3:~/846156 (master) $ git push --set-upstream origin master
fatal: Authentication failed
Another stackoverflow thread suggested I try the following, with disappointing results.
peeplesoft@jane3:~/846156 (master) $ git push -u origin master
fatal: Authentication failed
Then I tried this:
peeplesoft@jane3:~/846156 (master) $ git config remote.origin.push HEAD
peeplesoft@jane3:~/846156 (master) $ git push
fatal: Authentication failed
Any hints?
alex
473k199 gold badges872 silver badges978 bronze badges
asked May 1, 2014 at 3:38
7
You fixed the push, but, independently of that push issue (which I explained in «Why do I need to explicitly push a new branch?»: git push -u origin master
or git push -u origin --all
), you need now to resolve the authentication issue.
That depends on your url (ssh as in ‘git@github.com/yourRepo
, or https as in https://github.com/You/YourRepo
)
For https url:
If your account is protected by the two-factor authentication, your regular password won’t work (for https url), as explained here or here.
Same problem if your password contains special character (as in this answer)
If https doesn’t work (because you don’t want to generate a secondary key, a PAT: personal Access Token), then you can switch to ssh, as I have shown here.
As noted by qwerty in the comments, you can automatically create the branch of same name on the remote with:
git push -u origin head
Why?
- HEAD (see your
.gitHEAD
file) has the refspec of the currently checked out branch (for example:ref: refs/heads/master
) - the default push policy is simple
Since the refpec used for this push is head: (no destination), a missing :<dst>
means to update the same ref as the <src>
(head, which is a branch).
That won’t work if HEAD is detached though.
Or you can use Git 2.37 (Q3 2022) and the new global option push.autoSetupRemote
:
git config --global push.autoSetupRemote true
git push
answered May 1, 2014 at 4:42
VonCVonC
1.2m508 gold badges4249 silver badges5071 bronze badges
4
Also you can use the following command:
git push -u origin master
This creates (-u) another branch in your remote repo. Once the authentication using ssh is done that is.
answered Jul 19, 2014 at 0:40
TantrajJaTantrajJa
1,9672 gold badges14 silver badges9 bronze badges
2
If you define the action git push
it should take it if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line.
Just do it:
git config --global push.default current
then
git push
answered Sep 11, 2019 at 16:25
DariusVDariusV
2,54314 silver badges21 bronze badges
3
Apparently you also get this error message when you forget the --all
parameter when pushing for the first time. I wrote
git push -u origin
which gave this error, it should have been
git push -u origin --all
Oh how I love these copy-paste errors …
answered Nov 27, 2014 at 8:55
TheEyeTheEye
9,1902 gold badges41 silver badges58 bronze badges
1
Please try this scenario
git push -f --set-upstream origin master
Ajmal Sha
8664 gold badges17 silver badges36 bronze badges
answered May 2, 2018 at 12:10
hoochanlonhoochanlon
2612 silver badges5 bronze badges
5
use this command first before you push in to the branch
git config --global push.default current
After executing the above command use git push command.
Paul Roub
36.2k27 gold badges82 silver badges90 bronze badges
answered Apr 19, 2021 at 13:50
KileMaxKileMax
1931 silver badge7 bronze badges
1
You need to configure the remote first, then push.
git remote add origin url-to-your-repo
Actual Instructions
answered Mar 30, 2017 at 7:51
Santosh PillaiSantosh Pillai
7,8691 gold badge30 silver badges26 bronze badges
It means that you don’t have your branch(the branch that you want to push) in your remote repository, in other words it does not exist in your remote repository(it wasn’t created yet)…
So use this Code:
git push -u origin 'your branch name'
this code will create your branch in your remote repository and will push it…
answered Apr 13, 2021 at 11:30
jamal zarejamal zare
95911 silver badges12 bronze badges
1
on a very simple side, once you have other branches, you can’t just use for pushing a branch
git push
But you need to specify the branch now, even if you have checkout the branch you want to push, so
git push origin <feature_branch>
Where can be even the master
branch
answered Nov 15, 2018 at 9:16
AbhishekAbhishek
3,2874 gold badges31 silver badges51 bronze badges
Well, I was having the same trouble while uploading and I resolved it by
doing the same thing which it says to do:
Earlier I was trying to push through terminal to my repository in linux by https
like
git push https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git
But was not getting any result and hence I went down deeper and tried:
git push --set-upstream https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git master
And it worked. Thus then you will get prompted with username and password.
I also generated a token and instead of Password I pasted the token and thus, being done successfully.
- To generate a token go to your Github account and in Developer Settings and then create another token.
- After getting that, copy
that token and paste in the password prompt when it’s been asked.
zar
10.9k13 gold badges91 silver badges171 bronze badges
answered Oct 16, 2018 at 16:47
2
I made the simple error of forgetting to commit:
git commit -m "first commit"
then git push origin master
worked.
answered Jul 13, 2018 at 23:44
yl_lowyl_low
1,0892 gold badges17 silver badges25 bronze badges
I had the same problem
I resolved it that used below command
$ git branch --set-upstream develop origin/develop
and it will add a config in the config file in the .git folder.
answered Jan 7, 2019 at 2:33
bluetatabluetata
5296 silver badges12 bronze badges
1
First use git pull origin your_branch_name
Then use git push origin your_branch_name
answered Feb 16, 2017 at 3:20
FRabbiFRabbi
1351 silver badge6 bronze badges
2
There is a simple solution to this which worked for me on macOS Sierra.
I did these two commands:
git pull --rebase git_url(Ex: https://github.com/username/reponame.git)
git push origin master
If it shows any fatal error regarding upstream after any future push then simply run :
git push --set-upstream origin master
answered Sep 10, 2017 at 12:18
theRanatheRana
6949 silver badges10 bronze badges
If you constantly get the following git error message after attempting a git push with a new local branch:
fatal: The current branch has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin <branchname>
Then the issue is that you have not configured git to always create new branches on the remote from local ones.
The permanent fix if you always want to just create that new branch on the remote to mirror and track your local branch is:
git config --global push.default current
Now you can git push without any errors!
https://vancelucas.com/blog/how-to-fix-git-fatal-the-current-branch-has-no-upstream-branch/
fcdt
2,3315 gold badges12 silver badges26 bronze badges
answered Oct 19, 2020 at 23:07
For me, it was because I had deleted the hidden .git folder.
I fixed it by deleting the folder, re-cloning, and re-making the changes.
answered Sep 10, 2019 at 2:18
I was getting this error because I was trying to push the code without write
access, I only had read
access.
In Bitbucket, you can check access on the right side when you open your repo (Repository details) :
answered Sep 21, 2022 at 6:53
stackichstackich
2,9093 gold badges14 silver badges31 bronze badges
1. A computer and your github associated. Use SSH. Computer code so you do not need to submit verified enter image description here
2. git can not manage empty folder. So you have to write such a readme.md saved in a file. Otherwise you will not find the file.
3. Your local project is nothing new projects move over. Please
git init
git remote add origin +"githublink"
git add .
git commit -m ""
go again.
4. then git pull origin master
(the key)
5. At last git push origin master
(solve all problem).
http://my.oschina.net/psuyun/blog/123005 参考链接
N.Droid
2,04316 silver badges28 bronze badges
answered Jul 15, 2016 at 13:30
If you are trying to push your code direct to the master branch then use command
git push origin master
It helps me.
answered Apr 26, 2018 at 6:02
I also got the same error.I think it was because I clone it and try to push back.
$ git push -u origin master
This is the right command.Try that
Counting objects: 8, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (8/8), 691 bytes | 46.00 KiB/s, done.
Total 8 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
-
[new branch] master -> master
Branch master set up to track remote branch master from origin.It was successful. Try to create new u branch
answered May 11, 2018 at 16:08
I had the same problem, the cause was that I forgot to specify the branch
git push myorigin feature/23082018_my-feature_eb
answered Aug 23, 2018 at 9:25
BlackBlack
17.1k36 gold badges150 silver badges256 bronze badges
For me, I was pushing the changes to a private repo to which I didn’t had the write access.
Make sure you have the valid access rights while performing push or pull operations.
You can directly verify via
answered Jul 26, 2019 at 8:14
1
If you are on any branch, you can use this:
git push origin head -u
This will automatically create new branch of the same name on the remote.
answered May 15, 2020 at 10:17
QwertyQwerty
27.3k21 gold badges107 silver badges129 bronze badges
commit your code using
git commit -m "first commit"
then config your mail id using
git config user.email "example@example.com"
this is work for me
Boken
4,5269 gold badges33 silver badges42 bronze badges
answered Jul 14, 2020 at 8:11
The thing that helped me:
I saw that the connection between my directory to git wasn’t established —
so I did again:
git push -u origin main
ghilesZ
1,4051 gold badge17 silver badges30 bronze badges
answered Jan 28, 2021 at 12:12
Different case with same error (backing up to external drive), the issue was that I’d set up the remote repo with clone. Works every time if you set the remote repo up with bare initially
cd F:/backups/dir
git init --bare
cd C:/working/dir
git remote add backup F:/backups/dir
git push backup master
answered Feb 1, 2021 at 0:29
DaveDave
1,3592 gold badges16 silver badges14 bronze badges
In my mind, this is just a wrong default git behavior.
Having reviewed all options support by git, also reviewed the relevant git code:
https://github.com/git/git/blob/140045821aa78da3a80a7d7c8f707b955e1ab40d/builtin/push.c#L188
The best solution I would suggest it simply override the push default command:
git config --global alias.pu 'push -u'
This basically changes the default behavior of push so that makes sense.
answered Mar 8, 2021 at 7:23
JAR.JAR.beansJAR.JAR.beans
9,3594 gold badges44 silver badges56 bronze badges
Encountered just about the same problem, but not from the master branch.
I tried to push two (2) branches to my remote repository, by using the $ git push
command; which unfortunately threw up the:
fatal: The current branch <branch-name> has no upstream branch. To push the current branch and set the remote as upstream, use
git push --set-upstream origin <branch-name>
I got it fixed with this command below:
$ git push -u origin --all
PS: The solution provided here should, i believe, make it easier for git to track out branches remotely; this could come in-handy someday, when working on projects with couple of branches.
answered Jul 25, 2021 at 22:14
1
In my case, I have a local branch called Master, whereas master is on Github.
I simply rename my Master -> master and checkout to master.
And then push it. It works for me.
answered May 1, 2022 at 13:39
UC57UC57
3594 silver badges16 bronze badges
It is better, Clone this repo newly. Maybe it just lost track.
answered Oct 31, 2022 at 5:16
I’m trying to push one of my projects to github, and I keep getting this error:
peeplesoft@jane3:~/846156 (master) $ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
So I tried it and got this:
peeplesoft@jane3:~/846156 (master) $ git push --set-upstream origin master
fatal: Authentication failed
Another stackoverflow thread suggested I try the following, with disappointing results.
peeplesoft@jane3:~/846156 (master) $ git push -u origin master
fatal: Authentication failed
Then I tried this:
peeplesoft@jane3:~/846156 (master) $ git config remote.origin.push HEAD
peeplesoft@jane3:~/846156 (master) $ git push
fatal: Authentication failed
Any hints?
alex
473k199 gold badges872 silver badges978 bronze badges
asked May 1, 2014 at 3:38
7
You fixed the push, but, independently of that push issue (which I explained in «Why do I need to explicitly push a new branch?»: git push -u origin master
or git push -u origin --all
), you need now to resolve the authentication issue.
That depends on your url (ssh as in ‘git@github.com/yourRepo
, or https as in https://github.com/You/YourRepo
)
For https url:
If your account is protected by the two-factor authentication, your regular password won’t work (for https url), as explained here or here.
Same problem if your password contains special character (as in this answer)
If https doesn’t work (because you don’t want to generate a secondary key, a PAT: personal Access Token), then you can switch to ssh, as I have shown here.
As noted by qwerty in the comments, you can automatically create the branch of same name on the remote with:
git push -u origin head
Why?
- HEAD (see your
.gitHEAD
file) has the refspec of the currently checked out branch (for example:ref: refs/heads/master
) - the default push policy is simple
Since the refpec used for this push is head: (no destination), a missing :<dst>
means to update the same ref as the <src>
(head, which is a branch).
That won’t work if HEAD is detached though.
Or you can use Git 2.37 (Q3 2022) and the new global option push.autoSetupRemote
:
git config --global push.autoSetupRemote true
git push
answered May 1, 2014 at 4:42
VonCVonC
1.2m508 gold badges4249 silver badges5071 bronze badges
4
Also you can use the following command:
git push -u origin master
This creates (-u) another branch in your remote repo. Once the authentication using ssh is done that is.
answered Jul 19, 2014 at 0:40
TantrajJaTantrajJa
1,9672 gold badges14 silver badges9 bronze badges
2
If you define the action git push
it should take it if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line.
Just do it:
git config --global push.default current
then
git push
answered Sep 11, 2019 at 16:25
DariusVDariusV
2,54314 silver badges21 bronze badges
3
Apparently you also get this error message when you forget the --all
parameter when pushing for the first time. I wrote
git push -u origin
which gave this error, it should have been
git push -u origin --all
Oh how I love these copy-paste errors …
answered Nov 27, 2014 at 8:55
TheEyeTheEye
9,1902 gold badges41 silver badges58 bronze badges
1
Please try this scenario
git push -f --set-upstream origin master
Ajmal Sha
8664 gold badges17 silver badges36 bronze badges
answered May 2, 2018 at 12:10
hoochanlonhoochanlon
2612 silver badges5 bronze badges
5
use this command first before you push in to the branch
git config --global push.default current
After executing the above command use git push command.
Paul Roub
36.2k27 gold badges82 silver badges90 bronze badges
answered Apr 19, 2021 at 13:50
KileMaxKileMax
1931 silver badge7 bronze badges
1
You need to configure the remote first, then push.
git remote add origin url-to-your-repo
Actual Instructions
answered Mar 30, 2017 at 7:51
Santosh PillaiSantosh Pillai
7,8691 gold badge30 silver badges26 bronze badges
It means that you don’t have your branch(the branch that you want to push) in your remote repository, in other words it does not exist in your remote repository(it wasn’t created yet)…
So use this Code:
git push -u origin 'your branch name'
this code will create your branch in your remote repository and will push it…
answered Apr 13, 2021 at 11:30
jamal zarejamal zare
95911 silver badges12 bronze badges
1
on a very simple side, once you have other branches, you can’t just use for pushing a branch
git push
But you need to specify the branch now, even if you have checkout the branch you want to push, so
git push origin <feature_branch>
Where can be even the master
branch
answered Nov 15, 2018 at 9:16
AbhishekAbhishek
3,2874 gold badges31 silver badges51 bronze badges
Well, I was having the same trouble while uploading and I resolved it by
doing the same thing which it says to do:
Earlier I was trying to push through terminal to my repository in linux by https
like
git push https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git
But was not getting any result and hence I went down deeper and tried:
git push --set-upstream https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git master
And it worked. Thus then you will get prompted with username and password.
I also generated a token and instead of Password I pasted the token and thus, being done successfully.
- To generate a token go to your Github account and in Developer Settings and then create another token.
- After getting that, copy
that token and paste in the password prompt when it’s been asked.
zar
10.9k13 gold badges91 silver badges171 bronze badges
answered Oct 16, 2018 at 16:47
2
I made the simple error of forgetting to commit:
git commit -m "first commit"
then git push origin master
worked.
answered Jul 13, 2018 at 23:44
yl_lowyl_low
1,0892 gold badges17 silver badges25 bronze badges
I had the same problem
I resolved it that used below command
$ git branch --set-upstream develop origin/develop
and it will add a config in the config file in the .git folder.
answered Jan 7, 2019 at 2:33
bluetatabluetata
5296 silver badges12 bronze badges
1
First use git pull origin your_branch_name
Then use git push origin your_branch_name
answered Feb 16, 2017 at 3:20
FRabbiFRabbi
1351 silver badge6 bronze badges
2
There is a simple solution to this which worked for me on macOS Sierra.
I did these two commands:
git pull --rebase git_url(Ex: https://github.com/username/reponame.git)
git push origin master
If it shows any fatal error regarding upstream after any future push then simply run :
git push --set-upstream origin master
answered Sep 10, 2017 at 12:18
theRanatheRana
6949 silver badges10 bronze badges
If you constantly get the following git error message after attempting a git push with a new local branch:
fatal: The current branch has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin <branchname>
Then the issue is that you have not configured git to always create new branches on the remote from local ones.
The permanent fix if you always want to just create that new branch on the remote to mirror and track your local branch is:
git config --global push.default current
Now you can git push without any errors!
https://vancelucas.com/blog/how-to-fix-git-fatal-the-current-branch-has-no-upstream-branch/
fcdt
2,3315 gold badges12 silver badges26 bronze badges
answered Oct 19, 2020 at 23:07
For me, it was because I had deleted the hidden .git folder.
I fixed it by deleting the folder, re-cloning, and re-making the changes.
answered Sep 10, 2019 at 2:18
I was getting this error because I was trying to push the code without write
access, I only had read
access.
In Bitbucket, you can check access on the right side when you open your repo (Repository details) :
answered Sep 21, 2022 at 6:53
stackichstackich
2,9093 gold badges14 silver badges31 bronze badges
1. A computer and your github associated. Use SSH. Computer code so you do not need to submit verified enter image description here
2. git can not manage empty folder. So you have to write such a readme.md saved in a file. Otherwise you will not find the file.
3. Your local project is nothing new projects move over. Please
git init
git remote add origin +"githublink"
git add .
git commit -m ""
go again.
4. then git pull origin master
(the key)
5. At last git push origin master
(solve all problem).
http://my.oschina.net/psuyun/blog/123005 参考链接
N.Droid
2,04316 silver badges28 bronze badges
answered Jul 15, 2016 at 13:30
If you are trying to push your code direct to the master branch then use command
git push origin master
It helps me.
answered Apr 26, 2018 at 6:02
I also got the same error.I think it was because I clone it and try to push back.
$ git push -u origin master
This is the right command.Try that
Counting objects: 8, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (8/8), 691 bytes | 46.00 KiB/s, done.
Total 8 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
-
[new branch] master -> master
Branch master set up to track remote branch master from origin.It was successful. Try to create new u branch
answered May 11, 2018 at 16:08
I had the same problem, the cause was that I forgot to specify the branch
git push myorigin feature/23082018_my-feature_eb
answered Aug 23, 2018 at 9:25
BlackBlack
17.1k36 gold badges150 silver badges256 bronze badges
For me, I was pushing the changes to a private repo to which I didn’t had the write access.
Make sure you have the valid access rights while performing push or pull operations.
You can directly verify via
answered Jul 26, 2019 at 8:14
1
If you are on any branch, you can use this:
git push origin head -u
This will automatically create new branch of the same name on the remote.
answered May 15, 2020 at 10:17
QwertyQwerty
27.3k21 gold badges107 silver badges129 bronze badges
commit your code using
git commit -m "first commit"
then config your mail id using
git config user.email "example@example.com"
this is work for me
Boken
4,5269 gold badges33 silver badges42 bronze badges
answered Jul 14, 2020 at 8:11
The thing that helped me:
I saw that the connection between my directory to git wasn’t established —
so I did again:
git push -u origin main
ghilesZ
1,4051 gold badge17 silver badges30 bronze badges
answered Jan 28, 2021 at 12:12
Different case with same error (backing up to external drive), the issue was that I’d set up the remote repo with clone. Works every time if you set the remote repo up with bare initially
cd F:/backups/dir
git init --bare
cd C:/working/dir
git remote add backup F:/backups/dir
git push backup master
answered Feb 1, 2021 at 0:29
DaveDave
1,3592 gold badges16 silver badges14 bronze badges
In my mind, this is just a wrong default git behavior.
Having reviewed all options support by git, also reviewed the relevant git code:
https://github.com/git/git/blob/140045821aa78da3a80a7d7c8f707b955e1ab40d/builtin/push.c#L188
The best solution I would suggest it simply override the push default command:
git config --global alias.pu 'push -u'
This basically changes the default behavior of push so that makes sense.
answered Mar 8, 2021 at 7:23
JAR.JAR.beansJAR.JAR.beans
9,3594 gold badges44 silver badges56 bronze badges
Encountered just about the same problem, but not from the master branch.
I tried to push two (2) branches to my remote repository, by using the $ git push
command; which unfortunately threw up the:
fatal: The current branch <branch-name> has no upstream branch. To push the current branch and set the remote as upstream, use
git push --set-upstream origin <branch-name>
I got it fixed with this command below:
$ git push -u origin --all
PS: The solution provided here should, i believe, make it easier for git to track out branches remotely; this could come in-handy someday, when working on projects with couple of branches.
answered Jul 25, 2021 at 22:14
1
In my case, I have a local branch called Master, whereas master is on Github.
I simply rename my Master -> master and checkout to master.
And then push it. It works for me.
answered May 1, 2022 at 13:39
UC57UC57
3594 silver badges16 bronze badges
It is better, Clone this repo newly. Maybe it just lost track.
answered Oct 31, 2022 at 5:16
I’m trying to push one of my projects to github, and I keep getting this error:
peeplesoft@jane3:~/846156 (master) $ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
So I tried it and got this:
peeplesoft@jane3:~/846156 (master) $ git push --set-upstream origin master
fatal: Authentication failed
Another stackoverflow thread suggested I try the following, with disappointing results.
peeplesoft@jane3:~/846156 (master) $ git push -u origin master
fatal: Authentication failed
Then I tried this:
peeplesoft@jane3:~/846156 (master) $ git config remote.origin.push HEAD
peeplesoft@jane3:~/846156 (master) $ git push
fatal: Authentication failed
Any hints?
alex
473k199 gold badges872 silver badges978 bronze badges
asked May 1, 2014 at 3:38
7
You fixed the push, but, independently of that push issue (which I explained in «Why do I need to explicitly push a new branch?»: git push -u origin master
or git push -u origin --all
), you need now to resolve the authentication issue.
That depends on your url (ssh as in ‘git@github.com/yourRepo
, or https as in https://github.com/You/YourRepo
)
For https url:
If your account is protected by the two-factor authentication, your regular password won’t work (for https url), as explained here or here.
Same problem if your password contains special character (as in this answer)
If https doesn’t work (because you don’t want to generate a secondary key, a PAT: personal Access Token), then you can switch to ssh, as I have shown here.
As noted by qwerty in the comments, you can automatically create the branch of same name on the remote with:
git push -u origin head
Why?
- HEAD (see your
.gitHEAD
file) has the refspec of the currently checked out branch (for example:ref: refs/heads/master
) - the default push policy is simple
Since the refpec used for this push is head: (no destination), a missing :<dst>
means to update the same ref as the <src>
(head, which is a branch).
That won’t work if HEAD is detached though.
Or you can use Git 2.37 (Q3 2022) and the new global option push.autoSetupRemote
:
git config --global push.autoSetupRemote true
git push
answered May 1, 2014 at 4:42
VonCVonC
1.2m508 gold badges4249 silver badges5071 bronze badges
4
Also you can use the following command:
git push -u origin master
This creates (-u) another branch in your remote repo. Once the authentication using ssh is done that is.
answered Jul 19, 2014 at 0:40
TantrajJaTantrajJa
1,9672 gold badges14 silver badges9 bronze badges
2
If you define the action git push
it should take it if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line.
Just do it:
git config --global push.default current
then
git push
answered Sep 11, 2019 at 16:25
DariusVDariusV
2,54314 silver badges21 bronze badges
3
Apparently you also get this error message when you forget the --all
parameter when pushing for the first time. I wrote
git push -u origin
which gave this error, it should have been
git push -u origin --all
Oh how I love these copy-paste errors …
answered Nov 27, 2014 at 8:55
TheEyeTheEye
9,1902 gold badges41 silver badges58 bronze badges
1
Please try this scenario
git push -f --set-upstream origin master
Ajmal Sha
8664 gold badges17 silver badges36 bronze badges
answered May 2, 2018 at 12:10
hoochanlonhoochanlon
2612 silver badges5 bronze badges
5
use this command first before you push in to the branch
git config --global push.default current
After executing the above command use git push command.
Paul Roub
36.2k27 gold badges82 silver badges90 bronze badges
answered Apr 19, 2021 at 13:50
KileMaxKileMax
1931 silver badge7 bronze badges
1
You need to configure the remote first, then push.
git remote add origin url-to-your-repo
Actual Instructions
answered Mar 30, 2017 at 7:51
Santosh PillaiSantosh Pillai
7,8691 gold badge30 silver badges26 bronze badges
It means that you don’t have your branch(the branch that you want to push) in your remote repository, in other words it does not exist in your remote repository(it wasn’t created yet)…
So use this Code:
git push -u origin 'your branch name'
this code will create your branch in your remote repository and will push it…
answered Apr 13, 2021 at 11:30
jamal zarejamal zare
95911 silver badges12 bronze badges
1
on a very simple side, once you have other branches, you can’t just use for pushing a branch
git push
But you need to specify the branch now, even if you have checkout the branch you want to push, so
git push origin <feature_branch>
Where can be even the master
branch
answered Nov 15, 2018 at 9:16
AbhishekAbhishek
3,2874 gold badges31 silver badges51 bronze badges
Well, I was having the same trouble while uploading and I resolved it by
doing the same thing which it says to do:
Earlier I was trying to push through terminal to my repository in linux by https
like
git push https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git
But was not getting any result and hence I went down deeper and tried:
git push --set-upstream https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git master
And it worked. Thus then you will get prompted with username and password.
I also generated a token and instead of Password I pasted the token and thus, being done successfully.
- To generate a token go to your Github account and in Developer Settings and then create another token.
- After getting that, copy
that token and paste in the password prompt when it’s been asked.
zar
10.9k13 gold badges91 silver badges171 bronze badges
answered Oct 16, 2018 at 16:47
2
I made the simple error of forgetting to commit:
git commit -m "first commit"
then git push origin master
worked.
answered Jul 13, 2018 at 23:44
yl_lowyl_low
1,0892 gold badges17 silver badges25 bronze badges
I had the same problem
I resolved it that used below command
$ git branch --set-upstream develop origin/develop
and it will add a config in the config file in the .git folder.
answered Jan 7, 2019 at 2:33
bluetatabluetata
5296 silver badges12 bronze badges
1
First use git pull origin your_branch_name
Then use git push origin your_branch_name
answered Feb 16, 2017 at 3:20
FRabbiFRabbi
1351 silver badge6 bronze badges
2
There is a simple solution to this which worked for me on macOS Sierra.
I did these two commands:
git pull --rebase git_url(Ex: https://github.com/username/reponame.git)
git push origin master
If it shows any fatal error regarding upstream after any future push then simply run :
git push --set-upstream origin master
answered Sep 10, 2017 at 12:18
theRanatheRana
6949 silver badges10 bronze badges
If you constantly get the following git error message after attempting a git push with a new local branch:
fatal: The current branch has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin <branchname>
Then the issue is that you have not configured git to always create new branches on the remote from local ones.
The permanent fix if you always want to just create that new branch on the remote to mirror and track your local branch is:
git config --global push.default current
Now you can git push without any errors!
https://vancelucas.com/blog/how-to-fix-git-fatal-the-current-branch-has-no-upstream-branch/
fcdt
2,3315 gold badges12 silver badges26 bronze badges
answered Oct 19, 2020 at 23:07
For me, it was because I had deleted the hidden .git folder.
I fixed it by deleting the folder, re-cloning, and re-making the changes.
answered Sep 10, 2019 at 2:18
I was getting this error because I was trying to push the code without write
access, I only had read
access.
In Bitbucket, you can check access on the right side when you open your repo (Repository details) :
answered Sep 21, 2022 at 6:53
stackichstackich
2,9093 gold badges14 silver badges31 bronze badges
1. A computer and your github associated. Use SSH. Computer code so you do not need to submit verified enter image description here
2. git can not manage empty folder. So you have to write such a readme.md saved in a file. Otherwise you will not find the file.
3. Your local project is nothing new projects move over. Please
git init
git remote add origin +"githublink"
git add .
git commit -m ""
go again.
4. then git pull origin master
(the key)
5. At last git push origin master
(solve all problem).
http://my.oschina.net/psuyun/blog/123005 参考链接
N.Droid
2,04316 silver badges28 bronze badges
answered Jul 15, 2016 at 13:30
If you are trying to push your code direct to the master branch then use command
git push origin master
It helps me.
answered Apr 26, 2018 at 6:02
I also got the same error.I think it was because I clone it and try to push back.
$ git push -u origin master
This is the right command.Try that
Counting objects: 8, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (8/8), 691 bytes | 46.00 KiB/s, done.
Total 8 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
-
[new branch] master -> master
Branch master set up to track remote branch master from origin.It was successful. Try to create new u branch
answered May 11, 2018 at 16:08
I had the same problem, the cause was that I forgot to specify the branch
git push myorigin feature/23082018_my-feature_eb
answered Aug 23, 2018 at 9:25
BlackBlack
17.1k36 gold badges150 silver badges256 bronze badges
For me, I was pushing the changes to a private repo to which I didn’t had the write access.
Make sure you have the valid access rights while performing push or pull operations.
You can directly verify via
answered Jul 26, 2019 at 8:14
1
If you are on any branch, you can use this:
git push origin head -u
This will automatically create new branch of the same name on the remote.
answered May 15, 2020 at 10:17
QwertyQwerty
27.3k21 gold badges107 silver badges129 bronze badges
commit your code using
git commit -m "first commit"
then config your mail id using
git config user.email "example@example.com"
this is work for me
Boken
4,5269 gold badges33 silver badges42 bronze badges
answered Jul 14, 2020 at 8:11
The thing that helped me:
I saw that the connection between my directory to git wasn’t established —
so I did again:
git push -u origin main
ghilesZ
1,4051 gold badge17 silver badges30 bronze badges
answered Jan 28, 2021 at 12:12
Different case with same error (backing up to external drive), the issue was that I’d set up the remote repo with clone. Works every time if you set the remote repo up with bare initially
cd F:/backups/dir
git init --bare
cd C:/working/dir
git remote add backup F:/backups/dir
git push backup master
answered Feb 1, 2021 at 0:29
DaveDave
1,3592 gold badges16 silver badges14 bronze badges
In my mind, this is just a wrong default git behavior.
Having reviewed all options support by git, also reviewed the relevant git code:
https://github.com/git/git/blob/140045821aa78da3a80a7d7c8f707b955e1ab40d/builtin/push.c#L188
The best solution I would suggest it simply override the push default command:
git config --global alias.pu 'push -u'
This basically changes the default behavior of push so that makes sense.
answered Mar 8, 2021 at 7:23
JAR.JAR.beansJAR.JAR.beans
9,3594 gold badges44 silver badges56 bronze badges
Encountered just about the same problem, but not from the master branch.
I tried to push two (2) branches to my remote repository, by using the $ git push
command; which unfortunately threw up the:
fatal: The current branch <branch-name> has no upstream branch. To push the current branch and set the remote as upstream, use
git push --set-upstream origin <branch-name>
I got it fixed with this command below:
$ git push -u origin --all
PS: The solution provided here should, i believe, make it easier for git to track out branches remotely; this could come in-handy someday, when working on projects with couple of branches.
answered Jul 25, 2021 at 22:14
1
In my case, I have a local branch called Master, whereas master is on Github.
I simply rename my Master -> master and checkout to master.
And then push it. It works for me.
answered May 1, 2022 at 13:39
UC57UC57
3594 silver badges16 bronze badges
It is better, Clone this repo newly. Maybe it just lost track.
answered Oct 31, 2022 at 5:16
Fatal Git Error: Current branch has no upstream
Branch based development is one of Git’s most beneficial features. It allows developers to experiment in isolated development spaces that nobody else can see unless the branch is explicitly shared with others. Unfortunately, when a developer creates a new branch and pushes to their shared GitHub, GitLab or BitBucket repository, they often encounter the following, dreaded error:
[email protected] /c/branch/push (new-branch) $ git push origin fatal: The current branch has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin new-branch
Set GitHub or GitLab as an upstream
Git’s upstream branch error messages is somewhat self-explanatory. Git’s error message also fairly succinctly describes the solution to the problem. Before you push a new branch to GitHub or GitLab, you must tell your local Git installation about the remote Git repository your branch should be pushed to. The simple solution to the current problem is easily solved by issuing the following Git push upstream command:
[email protected] /c/branch/push (new-branch) $ git push --set-upstream origin new-branch Enumerating objects: 3, done. * [new branch] new-branch -> new-branch Branch 'new-branch' set up to track remote branch 'new-branch' from 'origin'.
A quick refresh of the account which represents origin in this upstream branch example shows the new branch on GitHub with the all of the content from the latest commit.
Git’s ‘no upstream branch’ error can easily be fixed by setting the upstream branch to origin.
Branch has no upstream fix commands
The full set of commands performed in this Git push example that fixes the no upstream-branch error are as follows:
[email protected] /c/branch/push (new-branch) git push --set-upstream origin new-branch cd git* git switch -c new-branch git branch -a touch devo.html git add . git commit -m "Are we not men?" git push --set-upstream origin new-branch touch echo.html git add . git commit -m "Echo done" git push origin
Most modern software development teams only have one central repository to which developers push and pull, and the alias for that central team repository is almost always origin. So this step seems set the upstream repository the first time a new Git branch is pushed seems both unnecessary and non-intuitive to many. But as confusing as this required step may be, just think of it as a reminder of the fact that Git is a very powerful, distributed version control tool that has the ability to push and pull to many upstream repositories, not just the one, central, GitHub or GitLab server most teams use for their project.
This article outlines the different methods we can use to solve the fatal: The current branch master has no upstream branch
error in Git. We usually get this error when we create a new local branch, make some commits, and attempt a push to the remote repository.
By default, Git is not configured to create corresponding branches in the remote repository when we create them in the local repo.
Let us look at three methods you can use to resolve the error.
Fix the fatal: The current branch master has no upstream branch
Error in Git
For an easy walkthrough, we will simulate a scenario where we get the fatal: The current branch master has no upstream branch
error on Git by creating a new branch in our local repository, making some commits, and trying to attempt a push.
We made a few changes and committed. Let’s try to push to the remote repository.
Here are three methods we can use to solve this error.
The first method is the one suggested by Git. However, we highly do not recommend using it, as we will see shortly, but first, let’s see how this command works.
To solve the error, we will run:
$ git push --set-upstream origin Dev2.1
The command sets up the Dev2.1
branch in our remote repository, which will track the local branch. However, this method can lead to unexpected and weird consequences in your repository.
Let’s check out the second method.
You can also use:
$ git push -u origin Dev2.1
This command will create a remote branch with the same name as our local branch. If you encounter errors, add the all
flag to the command, as shown below.
$ git push -u origin --all
We prefer using the -u
flag instead of the git push --set-upstream
command.
The above methods fix the current issue. What if we want a permanent solution?
Luckily, Git is very malleable; we can tweak the Git configuration file to get a permanent solution which takes us to our third method.
Run the command below to configure Git to create remote branches when we create local branches.
$ git config --global push.default current
We can now use the git push
command alone without ever dealing with this annoying error again.
In conclusion, we get the fatal: The current branch master has no upstream branch
error when we have not configured Git to create corresponding remote branches when we create local branches.
We have gone through the various methods we can employ to solve this error. You now know what to avoid.
Не могу запушить. Выдает ошибку. Как решить эту проблему?
$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push —set-upstream origin master
после ввода команды выше:
To https://github.com/ebaysher/Chess.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘https://github.com/ebaysher/Chess.git’
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push —help’ for details.
Уже час гуглю и не могу понять в чем именно проблема
-
Вопрос заданболее года назад
-
9515 просмотров
Тебе жу «русским» языком написали, твоя ветка отстала. Сначала затяни изменения, смержи, закомить, а потом пуш
Создавая репозиторий в гитхабе вы нажали/оставили галочку «создать readme.md».
Это привело к тому, что в гитхабе в репозитории повился первый коммит.
При этом локально вы тоже коммитили.
Теперь у вас локально и в гитхабе мастер начинается с разных коммитов. Не уверен что простой git pull тут поможет.
Вам нужно удалить репозиторий в гитхабе и создать его заново, без всяких там файлов. Тогда вы сможете запушить туда локальные коммиты.
Пригласить эксперта
Я исправил. Подсказал ответ Иван Корюков. Действительно когда вы поставили галочку на readme.md, GitHub создал ветку «main». Создай ветку командой «git push -u origin <имя вашей ветке» и после пуште с ветке(м.б. после посмотрите на сайте GitHub в разделе проекта -> выбор веток). Иван Корюков спасибо на косвенный ответ. У меня сработало!
-
Показать ещё
Загружается…
11 февр. 2023, в 04:35
10000 руб./за проект
10 февр. 2023, в 23:26
6000 руб./за проект
10 февр. 2023, в 23:18
10000 руб./за проект
Минуточку внимания
When attempting to do a git push, are you getting the following response:
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin main
Quick solution, instead run the command
git push origin main
And the response will push what you were attempting to do
Enumerating objects: 34, done.
Counting objects: 100% (34/34), done.
Delta compression using up to 8 threads
Compressing objects: 100% (19/19), done.
Writing objects: 100% (19/19), 5.64 KiB | 2.82 MiB/s, done.
Total 19 (delta 15), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (15/15), completed with 15 local objects.
Related articles
Andrew Fletcher
•
11 Jul 2022
How to synchronize two remote Git repositories
Currently, I have a situation where I have two repositories. The first is where I’ve held the code since the beginning. The second has come on board recently and is the client repo. However, rather than shut the original down, I want to keep both running with the same code….
Andrew Fletcher
•
09 May 2022
Creating then adding a key to the remote repository
In this woalk through I am going to use GitHub. However, the steps are similar to a Bitbucket profile.
Logged in to your GitHub account, click your profile icon, located (at the time of this writing) on the top right corner.
Select Settings
Click SSH and GPG…
Andrew Fletcher
•
11 Jun 2021
Starting a new GitHub repository including having to merge
Wanting to create a new repository on GitHub, add in a few of the available options that can come with an initial repository such as:
.gitignore for the platform you are building on
README.md for detailed notes — particularly if the repository if public
LICENSE — again important if the…