5

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?

Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
Nimit Joshi
  • 1,026
  • 3
  • 19
  • 46
  • 2
    possible duplicate of [Git for beginners: The definitive practical guide](http://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide) – AD7six May 26 '14 at 08:39
  • 2
    It's a pity the screenshot wasn't there at the beginning - you'd have gotten a lot more interest/help showing that a) you had tried the obvious b) were infact having problems creating a new branch on an empty repository (which is an entirely different problem than "how to create new files in git") – AD7six May 26 '14 at 09:50
  • @AD7six Actually, I edit the question because I also know about to work with my own branch. I do not want to store in the Master branch – Nimit Joshi May 27 '14 at 07:25
  • you have need to do more i.e, `git pull` and `git checkout master` – vineet Jun 23 '16 at 09:54

6 Answers6

9
  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"
Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
5
  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"
the swine
  • 10,713
  • 7
  • 58
  • 100
Matt Auerbach
  • 201
  • 2
  • 9
  • You said that after you create file in this directory. That's what i want. How do i create the file in master branch? – Nimit Joshi May 26 '14 at 08:44
  • You want to create a file in this directory? You can add a file to the directory any way you would like. After you create this file and run "git add . " and "git commit -m "message" the file will be added to the git system. – Matt Auerbach May 26 '14 at 08:47
  • Sir, would you please provide the code which adds some file in the master branch? – Nimit Joshi May 26 '14 at 08:51
2

You just have to use the command line :

git add #filename
git commit #filename
Jérôme
  • 292
  • 1
  • 6
  • How do i create a new file let say from notepad into that location. If the file exist on any other location so how do i add that file? – Nimit Joshi May 26 '14 at 08:40
1

Do these

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

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

and then create a branch

Emjey
  • 2,038
  • 3
  • 18
  • 33
0

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

0

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.

Sherry
  • 353
  • 3
  • 15