Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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.
like image 254
Rohan Sarkar Avatar asked Feb 07 '23 11:02

Rohan Sarkar


2 Answers

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
like image 92
AnoE Avatar answered Feb 09 '23 12:02

AnoE


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, e.g :

# 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
like image 41
LeGEC Avatar answered Feb 09 '23 10:02

LeGEC