Krish
Krish

Reputation: 189

Getting Exception while trying to creating branch using GIT

vamshi.krishna@KRISHNA /c/Project Repo/diameter (master) $ git branch develop fatal: Not a valid object name: 'master'.

Can you please explain me why i am getting this exception?

I have a repository created in my local called "Project Repo"

In that folder i have executed git init

And i created diameter folder and placed all my src folder into diameter folder

And Now i want to push that into a new brach called develop for that reason I am trying to branch named "Develop".Since I am in master branch I want to create develop branch which is not executing..

CAn you please let me know the correct steps to create the branch and push my coe to the develop branch

Upvotes: 2

Views: 1303

Answers (2)

Lukas Stejskal
Lukas Stejskal

Reputation: 2562

git checkout -b develop
git add .
git commit -m 'initial commit'
git push origin develop

And read some git tutorial. You should know what you're doing.

UPDATE

To recreate master branch from already populated develop branch:

git checkout master
git merge develop
git push origin master

Upvotes: 1

VonC
VonC

Reputation: 1324347

Note: the reason you have that error message is, because you haven't done any commit yet, there is no 'master' branch.
A branch need a starting point (HEAD of another branch for instance) in order to be created.

So first create a commit (even an empty one: git commit --allow-empty).
Then you can git checkout -b branch, git add everything, commit and push your new branch.

See more on that topic (creating branches while there isn't any commit yet) in "Creating branches on an empty project in git".

Upvotes: 1

Related Questions