Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: pushing a new, empty branch for an empty project?

Tags:

git

bitbucket

I have an empty project on remote, which I cloned. Now I want to start working on a branch, testdev and start working on it without putting any code to master.

$ git checkout -b testdev $ git status On branch testdev  Initial commit  nothing to commit (create/copy files and use "git add" to track) 

Now I try to push this branch to bitbucket

$ git push origin testdev  error: src refspec testdev does not match any. error: failed to push some refs to 'https://[email protected]/myremoterepo.git' 

I tried git add . and git commit -m "msg" but that is useless as I don't have any files to track or commit. So how do I push an empty branch to an empty project?

like image 822
yayu Avatar asked Nov 29 '14 11:11

yayu


People also ask

Can I create a new empty branch git?

November 2021 Update: As of git version 2.27, you can now use git switch --orphan <new branch> to create an empty branch with no history. Unlike git checkout --orphan <new branch> , this branch won't have any files from your current branch (save for those which git doesn't track).

How do I create a new branch in empty repository?

An empty repository cannot have a branch, branches are pointers to commits. So you first have to commit something in the empty repository before the branch can be created. You can either commit the code from the other repository, or just an empty file, create your branch and then commit the code.

How do I create a branch for an existing project?

Creating a branch from a previous commit Click History. Right-click on the commit you would like to create a new branch from and select Create Branch from Commit. Under Name, type the name of the new branch.

How do I empty a git branch?

The command to delete a local git branch can take one of two forms: git branch –delete old-branch. git branch -d old-branch.


1 Answers

If you repo is still empty, you might try and create an empty commit, to have something to push:

git commit --allow-empty -m "initial commit" git push -u origin testdev 

See also "Why do I need to explicitly push a new branch?".

like image 159
VonC Avatar answered Sep 19 '22 13:09

VonC