Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible in git to create a new, empty remote branch without pushing?

Tags:

git

branch

Most examples of creating remote branches involve pushing from a local branch

Is there a way of creating an empty remote branch without pushing?

Is it also possible to create a local empty branch,check it out then link it to the new also empty remote branch without pushing?

like image 661
vfclists Avatar asked Apr 04 '10 11:04

vfclists


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 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.

How do you create a new branch that tracks remote branches?

To create a new local branch based on a remote branch, use the "-track" option in the branch command. You can also do this by using the "checkout" command. If you want your local branch to have the same name as the remote branch, you only need to specify the name of the remote branch.


1 Answers

As mentioned in the blog post "Start a New Branch on your Remote Git Repository":

  • Creating a Remote Branch
git push origin origin:refs/heads/new_feature_name 
  • Make sure everything is up-to-date
git fetch origin 
  • Then you can see that the branch is created.
git branch -r 

This should show ‘origin/new_feature_name

  • Start tracking the new branch
git checkout --track -b new_feature_name origin/new_feature_name 

So to declare a remote branch, even one which doesn't yet exist on the local repository, git push is mandatory.

like image 66
VonC Avatar answered Sep 18 '22 15:09

VonC