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
Related
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.
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.
Early I had only github repository, but now want used both github and bitbucket.
I added a new remote git repository on Bitbucket, use git remote set-url.
git remote -v show
origin https://github.com/My/remont (fetch)
origin https://github.com/My/remont (push)
origin https://my#bitbucket.org/my/remont.git (push)
Then run:
git add --all .
git commit -m "bitbucker"
git push -u origin master
Github added fine but bitbucket shows an error
Password for 'https://my#bitbucket.org':
To https://bitbucket.org/my/remont.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://my#bitbucket.org/my/remont.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.
I have a microservices application, so the front-end on the first repo and two different backend APIs on two different repos. I want to add all these to someone else's empty repo and I am not sure how to do this.
I tried doing a git remote add of the other persons repo and I get this:
danales-MacBook-Pro:freelance-camp-fe danale$ git remote add https://github.com/Meridian-Business-Centers/Interview-Sample-App.git
usage: git remote add [<options>] <name> <url>
-f, --fetch fetch the remote branches
--tags import all tags and associated objects when fetching
or do not fetch any tag at all (--no-tags)
-t, --track <branch> branch(es) to track
-m, --master <branch>
master branch
--mirror[=<push|fetch>]
set up remote as a mirror to push to or fetch from
When I do a git remote add microservice master I get this error:
danales-MacBook-Pro:freelance-camp-fe danale$ git push microservice master
remote: Permission to Meridian-Business-Centers/Interview-Sample-App.git denied to ldco2016.
fatal: unable to access 'https://github.com/Meridian-Business-Centers/Interview-Sample-App.git/': The requested URL returned error: 403
I tried pushing it to my own forked version and got this error:
danales-MacBook-Pro:freelance-camp-fe danale$ git remote add microservice https://github.com/ldco2016/Interview-Sample-App.git
fatal: remote microservice already exists.
danales-MacBook-Pro:freelance-camp-fe danale$ git push microservice master
To https://github.com/ldco2016/Interview-Sample-App.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/ldco2016/Interview-Sample-App.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.
danales-MacBook-Pro:freelance-camp-fe danale$ git push -u microservice master
To https://github.com/ldco2016/Interview-Sample-App.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/ldco2016/Interview-Sample-App.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.
Go into every separate repo and add a remote (say, personal) with the url of other persons empty github repo. Now push the code like git push personal master.
Say, you have repo1, repo2 and repo3. And a personal repo perRepo (want to add repo1, repo2 and repo3 codes here).
# Go into repo1
$ git checkout master
$ git remote add personal <perRepo-url>
$ git push personal master
# Go into repo2
$ git checkout master
$ git remote add personal <perRepo-url>
$ git push personal master
# Go into repo3
$ git checkout master
$ git remote add personal <perRepo-url>
$ git push personal master
Add Submodule: General command: git submodule add <git#XXX:YYY> <externals>.
git submodule add: Simply tells Git we are adding a submodule
git#XXX:YYY: External repository URL that is to be added as a submodule
externals: This is the path where the submodule repository will be added to the main repository.
More Submodule
Add repo1, repo2 and repo3 as submodule of perRepo.
# Go into perRepo
$ git submodule add <repo1-url> <path>
$ git submodule add <repo2-url> <path>
$ git submodule add <repo3-url> <path>
$ git submodule update --init --recursive
N.B. when repo1/repo2/repo3 would be updated you need to run git submodule update command to get the updated changes into perRepo repo.
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.