mars_dev
mars_dev

Reputation: 639

Unable to configure git terminal to push a already created project

I have created a project and want to push it to git. I have created the repository on git and want to now push my code but I am not able to configure the git. I am getting the following error when I try to run git push -u origin master Error:

fatal: '[email protected]/dearestpankaj:cbb6c2bc8c0ea84120749a745fe59ab5de04d8b6/CoffeeDbApp' 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 have added my email and user name with following command:

git config --global user.email "[email protected]"
git config --global user.name "my_git_user_name"

After this I did the following:

git init
git add -A
git commit -m 'my first commit'
git remote add origin [email protected]/my_git_user_name/MyRepositoryName

But with above command I get following error: fatal: remote origin already exists.

git push -u -f origin master

with the above command, I get access right error. I understand that I have to add my password somewhere but I am not able to find where to add it to my terminal. I have now also created a personal token in the GitHub settings but still not sure how to use it. Right now I only have master branch in my remote which is created by default. I want to push in this branch and then, later on, will add more branches for my work.

Edit: I tried to add SSH key but when I still I am not able to push/pull. when I tried git push, I got the following:

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

when I tried above command, I got the following error: To github.com:dearestpankaj/CoffeeDbApp.git

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:dearestpankaj/CoffeeDbApp.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.

Upvotes: 0

Views: 1107

Answers (2)

pankaj
pankaj

Reputation: 8348

In addition to adding SSH key as mentioned by Kevin, follow these steps:

git pull origin master --allow-unrelated-histories
git merge origin origin/master
... add and commit here...
git push origin master

Upvotes: 2

Kevin Goslar
Kevin Goslar

Reputation: 445

Here are the steps to push a new codebase that exists on your computer to GitHub:

  1. Create an SSH key: instructions
  2. Upload the SSH key you just created to GitHub: instructions
  3. delete the old origin Git remote from your repository: git remote remove origin
  4. if you haven't done yet, create a new repository on GitHub: instructions
  5. On the GitHub website for your repository, click on the Code button, select Use SSH if it's visible, and copy the URL. It should start with [email protected]
  6. add the new origin Git remote: git remote add origin [paste URL] (replace [paste URL] with the URL you just copied
  7. run git push to push to GitHub

Upvotes: 3

Related Questions