I'm new to github so for the sake of testing I've been modifying my .gitconfig file (adding some useful aliases, etc.) and pushing it to my "Config Files" repository on github.
I have 2 computers, a desktop and a laptop. When I modify the local file in the desktop, commit and push to the remote repository it works fine.
However, when I try to do the same from the laptop I get this error.
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/User/Config-Files.git'
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.
Aditionally I get this error if I try to pull first like the message suggests:
$ git pull origin master
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 4 (delta 2), reused 4 (delta 2), pack-reused 0
Unpacking objects: 100% (4/4), 355 bytes | 8.00 KiB/s, done.
From https://github.com/User/Config-Files
* branch master -> FETCH_HEAD
627ab06..b327e2b master -> origin/master
fatal: refusing to merge unrelated histories
The remote repository only has the .gitconfig file, the same file I'm trying to push from the laptop so why am I getting this error?
The answer is in your terminal, it is telling you to fetch first.
You pushed to master already from your desktop, and your commit on your laptop is behind. So you have to fetch, merge, and then you'll be able to push from your laptop..
This is bad practice but can always force it in.. (--force) but then any of the changes made on your desktop would be gone.
Related
I am unable to push to git master, even master branch is there. I have tried git push -u origin master .
git --version
git version 2.32.0.windows.2
The commands executed .
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin http://url
git push -u origin main **//master is not working**
main branch is working
I have created a remote repository say git_example and then in the same name created a local repository(git_example) and tried to push it to remote.
D:\WORKSPACE\REACT\ems-backend-springboot>git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/subhashisz/ems-backend-boot.git'
D:\WORKSPACE\REACT\ems-backend-springboot>git push -u origin main
Enumerating objects: 67, done.
Counting objects: 100% (67/67), done.
Delta compression using up to 4 threads
Compressing objects: 100% (54/54), done.
Writing objects: 100% (67/67), 68.39 KiB | 1.27 MiB/s, done.
Total 67 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3), done.
remote:
remote: Create a pull request for 'main' on GitHub by visiting:
remote: https://github.com/subhashisz/ems-backend-boot/pull/new/main
remote:
To https://github.com/subhashisz/ems-backend-boot.git
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
You already set your "main" branch as main via the command:
git branch -M main
and set any following "git push" to push to the main branch via the command:
git push -u origin main
so in order to push to master, you need to execute:
git push origin master
also in this stackoverflow question you can find how to change your upstream branch if already set:
git branch branch_name --set-upstream-to origin/branch_name
The error I am getting:
To https://github.com/Git-Username/Repo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/user/repo.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.
Command I am executing:
git push origin master
I have tried nearly everything when I googled this error, I tried pulling etc.
I tried pulling etc.
pulling should have been enough to solve the issue.
But if your local history is correct (git log), and you are the only one pushig to that repository, you could also simply force push
git push --force -u origin master
That will override the history on the remote.
Project owner (michael365) maintain a repository and has provided developer access to me. I am trying to push the code but I am getting this error
remote: GitLab: API is not accessible
To gitlab.com:michael365/bim.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#gitlab.com:michael365/bim.git'
although I have set the public key in the SSH section, it still it doesn't work. I am issuing the following commands
$ git add .
$ git commit -m "Adding Initial Code"
On branch master
nothing to commit, working tree clean
$ 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
$ git push --set-upstream origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 868 bytes | 868.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: GitLab: API is not accessible
To gitlab.com:michael365/bim.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#gitlab.com:michael365/bim.git'
Any suggestions would be helpful
pre-receive hook declined indicates that your push was rejected by remote repository after a content check on the changes you are pushing failed.
Ask the admin of remote repo as in what check is rejecting your push. Usually you get a proper error with message stating what check failed.
Trying to push a committed file to an existing remote repository on GitHub.
Below I verified and I'm trying to push to the Django. I've tried git push, and git push -u Django master. Any help would be appreciated. I have been saving all of my files locally and I am now adding all to GitHub and it's a little confusing.
Roberts-MBP:Django robertamato$ git remote -v
Django https://github.com/CodingDojo-Python-09-04/Robert_Amato.git (fetch)
Django https://github.com/CodingDojo-Python-09-04/Robert_Amato.git (push)
origin https://github.com/CodingDojo-Python-09-04/RobertAmato (fetch)
origin https://github.com/CodingDojo-Python-09-04/RobertAmato (push)
Roberts-MBP:Django robertamato$
Here is a error code it threw, I see it suggests to fetch first but I'm not to familiar with how that process works.
Roberts-MBP:Django robertamato$ git push -u Django master
To https://github.com/CodingDojo-Python-09-04/Robert_Amato.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/CodingDojo-Python-09-04/Robert_Amato.git'
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.
I messed my repository while trying to resolve conflicts. Everything was quite OK (I'm getting familiar with Git) but things got bad when I tried to reset the current branch to a previous commit (not knowing exactly what I was doing, I admit). In SourceTree, I now have 2 commits to Pull from GitHub and 10 commits to Push. When I tried to Pull, I got this:
git -c diff.mnemonicprefix=false -c core.quotepath=false fetch origin
git -c diff.mnemonicprefix=false -c core.quotepath=false pull --no-commit origin master
From https://github.com/JnLlnd/CSVBuddy
* branch master -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
TEST-TheBeatles-Tab (1).txt
TEST-TheBeatles-Tab-EXPORT (1).txt
TEST-TheBeatles-Tab-EXPORT.txt
html-doc/img/review2_5_CSV Buddy_award.png
icon/csvbuddy-16x16.png
icon/csvbuddy-32x32.png
Please move or remove them before you can merge.
Aborting
I moved the 6 files and tried to Pull again. It seems to work (no error message). However, I still have the indication that there are 2 Pull to do.
If I try to Push the 10 commits, I get this error message:
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags origin master:master
Pushing to https://github.com/JnLlnd/CSVBuddy
To https://github.com/JnLlnd/CSVBuddy
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/JnLlnd/CSVBuddy'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Hum... I think I'm not that familiar with Git ;-) What should I do?
OK. Think I got it. I still had 2 conflicts to resolve before I can Pull / Push as desired.
Thanks for reading.