Error pushing code to Github repository - github

I'm trying to setup jekyll by following this setup. For that I created a public repository and under the same name on my computer cloned the project.
However once I try and push the code, it gives me following error -
fatal: 'aniruddhabarapatre.github.com' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I tried doing Git setup in case something got overridden, but am unable to finish the process and it hangs on
git credential-osxkeychain

Make sure you are pushing to the right github repo.
Its url should be
https://github.com/aniruddhabarapatre/aniruddhabarapatre.github.com
If git remote -v doesn't show this, do a:
git remote set-url origin https://github.com/aniruddhabarapatre/aniruddhabarapatre.github.com
And try to push again.
For the credential issue, see this answer, or this one, or (for checking how git is installed) this answer.

When you create a git repository add git ignore files, then it no more push unwanted files
Git global ignore

errors like this will occur when you try to push to a GitHub which you did not connected with the local repository you have in your machine. We can resolve this in a such way!
One: Delete your local repository and clone your GitHub project to your local machine($git clone ..url..) and now you can push any change directly to your GitHub account. If you do not want the original file from your local machine because you have some code on it you can move that to some where other than the directory you going to clone it. Then paste the content of your change inside newly cloned folder. Some time the issue/error may still persist so lets move to the second option.
Two: Here you mostly play with GitHub and follow this instruction since I did this many times.
From your terminal
To initialize the local directory as a Git repository
$git init
Add the files to your new local repo
$git add .
commit the file
$git commit -m "any comment you want to say"
Add the URL for the remote(GitHub) repository
$git remote add origin ..url..
Set the new remote
$git remote -v
Push the change
$git push -u origin master
Now if you go to your GitHub repo you will see your change.
While pushing the terminal might say pull first bla bla ... in that case you can force your push by saying
"$git push -f origin master"!!
Hopefully this will be helpful.

Related

Push my first project from my Git to my online GitHub repository

I am a GitHub newbe. I've created a project on my computer in a folder named "SpettroCorpoNero", which contains a file "SpettroCorpoNero.ipynb".
Now I would like to initializate it into my GitHub account. For this purpose I wrote on my git (which is on Linux) the following lines of code:
git init (which should initializate my project)
git status (Which shows in red the new files I would like to replicate on my GitHub account)
git add SpettroCorpoNero.ipynb (which is the list of file to put in the "basket")
git commit -m "That's BlackBodySpectrum" (That looks like another basket to put in)
git push
And the code looks like working up to the second last line of code. Than the following message of error I've received
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
git remote add <name> <url>
and then push using the remote name
git push <name>
In order to sort it out, different attempts I've done, such as following that push with my nickname (which is Stefanovic80), as suggested in the message of error. But I failed in all of them and now I fill confused and disoriented.
Is there anyone who could fix this issue, please?
As the command says, you need to tell it where to push to, the default name is origin, the url is the same as the clone url of the repo.
git remote add origin https://GitHub.com/account/repo.git
You need to have a base repository on GitHub to push your repo into first using this route.
If you have the github-cli installed you can create the target repo and set the remote in one go by calling
gh repo create
from your local git repository. It will create the repo on GitHub and set up your local settings so you can push your repo straight after.
See also:
https://cli.github.com/manual/gh_repo_create
Simply, you just need to set up your remote. If you go to your remote repository (which is most likely empty), you'll see a URL which you can copy, which looks something like:
https://github.com/my-username/my-repo-name
Then, in command line, run the command
git remote add origin https://github.com/my-username/my-repo-name
You can substitute origin with whatever you like, but that will be the name of your remote connection.
Finally, you need to push main (or whatever the branch may be named) to the remote origin:
git push -u origin main

Push an existing repository when creating a new repository always fail?

So every time I try to create a new repository and follow the Github instruction here.
…or push an existing repository from the command line
git remote add origin
https://github.com/menghaohsu/JavaAkkaCountWordInDirectory.git
git push -u origin master
It doesn't push the file in JavaAkkaCountWordInDirectory to Github but push repository. Can anyone help me with this?
Let me give you a few steps over here.
I assume you created your repo via GitHub.com web interface.
Locally you should have done all of the following steps prior to pushing the files to the remote.
git init --> This will initialize your local repo
git remote add origin {remote address}
git add {filename here | . } --> With this you add the file(s) to the staging area
git commit --> This command commits your changes (You have to add a message)
git -u push origin master
That should do the trick

best way to export Eclipse project to GitHub

I need to export an Eclipse project to GitHub. I am using Eclipse-Mars with the eGit plugin. I have spent hours reading documentation, tutorials, and posts and see that there are basically two ways
Create an Eclipse project and a local Git repository. Commit to local repository. Create a repository on GitHub. Push the Eclipse project to the repository on GitHub. When I try this, I get the error "rejected non-fast-forward". I have no idea why. I did create a .gitignore on GitHub when I created the repository - is that causing a problem?
Create a repository on GitHub. In Eclipse, clone this repository and then add files. Commit to local repository, then push. This works, but I end up with a weird configuration on GitHub:
reponame/myprojname/src
when I would prefer the more normal
reponame/src
Which method is the correct way to proceed? Why do I get the push error in the first method, and why the strange folder layout in the second?
You first need to pull the github code into you local machine.
=> git remote add origin
=> git pull origin master
will automatically fetch and merge the github repo with your local copy. You may need to resolve some conflicts that could be generated due to 3-way merge.
After all this, you can use -
=> git push -u origin master
For the second Point,
If you want src/ directory directly under reponame/ on github, then you should execute git clone after creating the project in eclipse and git clone should be executed inside the myprojectname/ directory.
When you created the .gitignore file on GitHub, you created a commit in the repository that isn't in your local copy. You'll need to add the GitHub repo as a remote, pull the change, and then push your local changes:
git remote add origin <path to your repository>
git pull origin master
git push -u origin master

C9 created workspace before repository

I made the mistake of creating a workspace before a repository on C9.io.
As a result I do not have version control. Naturally, I want to use Git for my project before make any more changes. Everything I have tried has failed. I would rather not have to copy all the code I've made into a new work space with an already set up repository. So if anyone has any suggestions or answers to this problem, via Command line, GUI or anything else that would be wonderful.
cloud9 doesn't do any special magic when cloning from a git repository, and you can add a remote the standard way you would do locally:
git init initialize a git repository in the current folder
git add -a add everything (or what you want)
git commit -m "initial commit" commit
git remote add origin git#github.com:<me>/<repo>.git add your repo
git push origin HEAD:master push HEAD to master branch in the remote you just added

Git push and pull origin master not working?

I'm currently trying to push some of my project files to github but I've been banging my head against the table now trying to figure out what is going wrong. Any help would be greatly appreciated.
What I do is I first created a new folder in my c:/ directory called cs188 and put all the files that I want committed in that folder. MY goal is to push the whole cs188 folder I created to github.
In git bash, I type:
(in the cs188 folder):
git init
git add .
git commit -m "first commit"
Now I add the remote
git remote add origin https://github.com/my_username/myrepos.git
(myrepos is the name of my repository on github)
Then afterwards I type:
git push origin master
I get a warning saying that "the tip of my current branch is behind its remote counterparts. Merge the remote changes before pushing again".
So now I type:
git pull origin master
But once this is done, my whole new folder has been replaced with the contents of my repos.
And once I type git push origin master, now and log onto my github account, nothing has changed or been added.
Does anyone have any idea what I'm doing wrong here?
Why is my new folder getting replaced with all the folders in my repository?
What should I do instead to get rid of "the tip of my current branch is behind its remote counterparts", and have my whole cs188 folder show up on github?
Any help is appreciated, I'm just completely frustrated with github right now and could really use some help.
One easiest way is to:
clone your new empty GitHub repo
add your file in that local clone, and commit
push
The first push would be done with:
git push -u origin master
After that, a simple git push will be enough.
See "Git: Why do I need to do --set-upstream all the time?".
Note: if your Github repo wasn't empty, the idea is still valid: clone it and add your files in it.
Otherwise, you would need to follow "Cannot pushto github, keeping saying need merge".