Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create branch on a empty repository and copy the code from another repository to the new br?

PRADEEP JANAGAMA
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 12, 2018

We have a new repository created, it is empty right now i want to create new branches and push the latest code there.

I tried git checkout -b branchname, but didn't helped.

And how we can identify, if we have more repositories and where we are creating the branches?

Please provide step by step process, that will be great-full.

1 answer

1 vote
Mikael Sandberg
Community Champion
October 12, 2018

Hi Pradeep,

Welcome to the Atlassian Community.

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.

Julius Davies [bit-booster.com]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 13, 2018

 

Committing something ahead of time would muddy the waters.   They should just add the new empty repository as a 2nd remote for their current clone and then push their branch to it.

From the original clone (on their workstation) try something like this:

git remote add fork [url-to-empty-repo]
git push fork HEAD:refs/heads/branchname

  

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events