Nimit Joshi
Nimit Joshi

Reputation: 1046

`fatal: Not a valid object name: 'master'` when creating a new branch in git

I followed this tutorial but I'm having trouble creating a new branch in a new repository. This is the error I'm getting:

enter image description here

What am I doing wrong?

Upvotes: 5

Views: 46327

Answers (6)

Sherry
Sherry

Reputation: 481

If your project directory, where you do the git init, already has some files in it, then you have to git add . and git commit those changes in the master branch before git will let you create a new branch. That was the issue in my case. This might as well be the stanadard process for everytime you do a git init even with an empty directory, but in my case, I was initialising an already full directory.

Upvotes: 0

user11748196
user11748196

Reputation:

first you have to commit changes use git commit -a then use git branch again

Upvotes: 0

Emjey
Emjey

Reputation: 2063

Do these

git config --global user.name "YOUR NAME" .

git config --global user.email "YOUR EMAIL ADDRESS"

and then create a branch

Upvotes: 1

Abimaran Kugathasan
Abimaran Kugathasan

Reputation: 32488

  1. To create a git repository locally, you have to be inside the project directory, then run git init command.

  2. To add a file to git, you have to create a file, with some text editor for example. Then you have to add that file to git, then commit it locally.

    git add .
    
    git commit -m "A short description what you did to the file"
    

UPDATED based on the question update :

To create a git repository for a project

  1. First you have to create a project directory.
  2. Then from inside the directory, you have to issue git init to initialize a git repo for that project
  3. By default, you will be in master branch, to create another branch, use git branch <new branch name>

To add new files to the created repository

  1. Create new files like you create for a project.
  2. Add those file to git using git add .
  3. To commit the file, use git commit -m "a Short description about the action you performed"

Upvotes: 9

Matt Auerbach
Matt Auerbach

Reputation: 201

  1. Initialize a git repository (directory/folder on your computer)
    Navigate to this directory. Then use git init.
  2. After you create files in this directory
    git add .
  3. Commit the changes
    git commit -m "your message"

This might also help: http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository

Code recap:

git init
git add .
git commit -m "your message"

Upvotes: 5

J&#233;r&#244;me
J&#233;r&#244;me

Reputation: 292

You just have to use the command line :

git add #filename
git commit #filename

Upvotes: 2

Related Questions