简体   繁体   中英

I want to push to a branch which is not master. That is what I did

git init
git add .
git commit -m "first"
git push origin ritu

(second is the name of a branch) but it say

fatal: origin does not appear to be a git repository.
fatal: could not read from remote repository.
Please sure you have the correct access rights and the repository exists.

You have to add the remote first, and you probably also want to create a local branch first, so in full:

git init
git remote add origin <url>

# or, instead if init+remote:  git clone <url>

git add ...
git commit
git branch ritu
git push origin ritu

git init will only create a local repository.

You have not defined any link to a remote copy, and git push will not work.

Depending on what you need :

  1. you only want to keep a local history of your project : you do not need to use any remote copies, and you can just ignore the git push step.

  2. you want to share this project with other people : you will need to create a remote repository accessible to these other people.

  3. your intention is to work on an existing project : you should start by cloning this existing project, and find some way to move your work on this clone.


You generally get a repository with a remote copy when you start out by cloning a existing repository, eg :

# this will create a local 'project/' repository,
# with all the history of the remote project,
# and, by default, git will keep the information :
#     "'origin' is a shortcut for https://github.com/user/project"

git clone https://github.com/user/project

Before pushing it to remote you need to add one. You can achieve this by git remote add origin git@host_name:user_name/repo.git

Once you have done this, try git push -u origin your_branch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM