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?
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).
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.
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.
The command to delete a local git branch can take one of two forms: git branch –delete old-branch. git branch -d old-branch.
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?".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With