Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 582
Nimit Joshi Avatar asked May 26 '14 08:05

Nimit Joshi


People also ask

How do I create a master branch in git repository?

The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

How do you push origin master?

Whenever we need to push the changes to a remote repository, we use git push along with the remote repository “origin” and “master” branches. The term used is “git push origin master“. To pull the changes from the remote repository to local, we use git pull along with remote repository “origin” and “master” branch.

Is master branch automatically created?

Every time you commit, the master branch pointer moves forward automatically. The “master” branch in Git is not a special branch. It is exactly like any other branch. The only reason nearly every repository has one is that the git init command creates it by default and most people don't bother to change it.

How do I push a local branch to remote branch?

Push a new Git branch to a remote repo Clone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.


2 Answers

  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"
like image 116
Abimaran Kugathasan Avatar answered Sep 27 '22 18:09

Abimaran Kugathasan


  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"
like image 39
Matt Auerbach Avatar answered Sep 27 '22 19:09

Matt Auerbach