What's wrong in git init ...? - command

When I use git init it only shows (master) and not (master -> origin), and then that when I use the command: git push -u origin master it returns an error:
error: src refspec master does not match any.
error: failed to push some refs to 'github.com:BghAek/something.git'

Most probably this happened:
Forget to add the remote repo link
You have created a new repository using the init command, but it looks like you forgot to add the link to the remote repository. So do the following:
Remove the `.git` file from you local system.
Create a clean repository using the following:
git init
git add .
git commit -m "COMMIT MESSAGE"
git branch -M main
git remote add origin REMOTE_REPOSITORY_LINK
git push -u origin main
replace REMOTE_REPOSITORY_LINK with that of the remote repository link. Remember your are on main branch, so as to keep it consistent with the remote branch( read more here).

Related

Unable to push Swift code to Heroku because of "GIT_DISCOVERY_ACROSS_FILESYSTEM not being set"

I am trying to push my Swift code to Heroku via Git. This is the error I am getting:
remote: fatal: not a git repository (or any parent up to mount point /)
remote: Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
So far I have tried the following:
git init
git remote add heroku [URL]
export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
heroku config:set GIT_DISCOVERY_ACROSS_FILESYSTEM=1 --remote origin
But still when I try to push code to master, it fails. This is the command I am using to push code:
git push heroku master
Double check, after your git init (I would prefer git init . to be sure), that you have indeed a .git/ subfolder created in your current folder.
As long as you don't see it, you would get that error message.

Push a local file to an existing GitHub remote repo

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.

Why git remote add is not working?

Why do I see an error message when typing git remote add?
$ git remote add origin remote repository https://github.com/hashanmalawana/Loginsystem.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
You should type:
git remote add origin https://github.com/hashanmalawana/Loginsystem.git
not
git remote add origin remote repository https://github.com/hashanmalawana/Loginsystem.git
^^^^^^^^^^^^^^^^^^
That way, you add a remote named origin, referencing the remote repo https://github.com/hashanmalawana/Loginsystem.git
And you won't see the usage message
usage: git remote add [<options>] <name> <url>
I understand that the step 8 of "Adding an existing project to GitHub using the command line" can be confusing:
git remote add origin remote repository URL
But the last three parameters are actually only one. It should read:
git remote add origin <remote repository URL>
It is better to refer to the actual man page for git remote
git remote add <name> <url>

How do I add my repos to another persons repo?

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.

Github- repository is on remote but not found when pushing

I'm trying to push something to github and I'm getting this error;
Robbies-MacBook-Pro:assn-6-huffman-mac user$ git push -u origin master
fatal: repository 'https://github.com/BitMechanic/Stanford-CS106b/Huffman.git/' not found
Then when I check I get this;
Robbies-MacBook-Pro:assn-6-huffman-mac user$ git remote add origin https://github.com/BitMechanic/Stanford-CS106b/Huffman
fatal: remote origin already exists.
Robbies-MacBook-Pro:assn-6-huffman-mac user$ git remote -v
origin https://github.com/BitMechanic/Stanford-CS106b/Huffman.git
(fetch)
origin https://github.com/BitMechanic/Stanford-CS106b/Huffman.git
(push)
Anyone know what I'm doing wrong?
The proper url to use (for cloning and then pushing through origin) is
https://github.com/BitMechanic/Stanford-CS106b.git
not:
https://github.com/BitMechanic/Stanford-CS106b/Huffman.git
Stanford-CS106b is a repo, listed in the BitMechanic's repo page of d. Stanford-CS106b/Huffman is not.
To fix this, see git remote commands:
git remote rm origin
git remote add origin https://github.com/BitMechanic/Stanford-CS106b.git
or, simpler:
git remote set-url origin https://github.com/BitMechanic/Stanford-CS106b.git
Can you paste the
$cat .git/config
output here for reference.
Sometimes it is better to remove the remotes that are misbehaving from there and re-add it using the git remote add command again.