4

Is it possible to make a branch in a remote master repository without having a local clone of the repository?

The repository is large enough that cloning a copy just to make and push the branch is extremely wasteful (about 20 minutes), especially as the branch is being made by an automated system for procedural and functional reasons, and it will not need the contents of the repository itself.

0

2 Answers 2

5

Not based on existing branches but you can push in an empty branch using a completely new unrelated repository. Try out the following test instructions

Creating the original repo for the test

cd ~/Desktop/test
mkdir original_repo && cd original_repo 
git init && touch testfile && git add . && git commit -m "master repo"
cd ..

Create a new empty repo

mkdir hacky_repo && cd hacky_repo
git init && touch init && git add . && git commit -m "empty new repo"

Add the original repo as a remote to this repo

git remote add original ../original_repo/

And now push the branch from this repo to the orignal repo

git push original master:some_new_branch
cd ../original_repo

If now you do a git branch - you should have the new branch there in your original repo.

$) git branch
* master
  some_new_branch

The assumption here is that you know in advance which all branches / branch namespace are free.

Sign up to request clarification or add additional context in comments.

2 Comments

Nice one. +1. Surely easier than my answer.
I see now - this always pushes a new branch with the "empty" contents of the hacky_repo. It doesn't actually branch the contents already contained within the remote's master branch. I was hoping to have functionality similar to cvs's rtag command to create a branch of all the existing files. Thanks for the interesting solution though; it answers my question as asked, which was poorly written.
2

In addition of pushing a branch from any repo, other possibilities include setup on the server some kind of listener in order to:

  • Trigger the creation of a branch (http listener)
  • Make the branch on the remote side (command through ssh)

But that supposes you have access to that server.

If the server is GitHub, you wouldn't be able to do that, but you would have the GitHub API to work with, like "Create a reference".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.