1

I want to make a git bare repository with multiple branches (master, develop, release, etc..). So question is if it is possible to checkout the bare repository or how to switch among the branches (does it make a sense to switch)?

When I want to push to the bare repository can I make a merging on bare repository or merging must be done locally and push the adequate branch? So looking for a right approach :-)

Thanks Peter

simont
  • 68,704
  • 18
  • 117
  • 136
Pepe
  • 213
  • 1
  • 5
  • 17
  • 1
    The site community expects you to accept the answers provided to your questions. Thanks! – CharlesB Feb 17 '12 at 08:21
  • Hello @Pepe, welcome to StackOverflow. Please read through the FAQ: http://stackoverflow.com/faq, specifically note the part about how to ask questions on stackoverflow. I also noticed that you've asked many questions in the past but have not voted or selected any answers. You can navigate to your profile to view the list of questions you've asked, read through and vote on and select the answers that solved the questions. Thanks! – Highway of Life Feb 17 '12 at 08:23
  • Maybe I do not understand what you mean by your comment? – Pepe Feb 17 '12 at 08:32

2 Answers2

7

I want to make a git bare repository with multiple branches (master, develop, release, etc..).

Judging from the question, it seems that you are unsure of the reasons you would make a bare git repository, and how you would use said repository. The question is, why do you wish to make a bare repository?

From Pro Git, a bare repository is "a repository that doesn’t contain a working directory." It's a repository that you don't work out of, and is just used to git push and git pull from. The reason for this is summed up here:

"A bare repository is one without a checked out working copy of the code. It only contains the git database. As a general rule you should never push into a repository that contains changes in the working copy. To ensure this doesn't happen, we're making the server repository a bare repository - it has no working copy."

So, a bare git repository can definitely contain multiple branches. You can definitely fetch a copy of the bare remote repository into your local repository, and push from your local repository to your remote (bare) repository. However, you don't want to work out of your bare repository. (Furthermore, it is impossible to run git add whilst in a bare repository; see this SO question for clarification).

So question is if it is possible to checkout the bare repository or how to switch among the branches (does it make a sense to switch)?

This question, I think, is not entirely clear, because you never really switch branches on the bare repository - you never work on the bare repository. All you do is push or pull from it.

When I want to push to the bare repository can I make a merging on bare repository or merging must be done locally and push the adequate branch? So looking for a right approach :-)

To git-push to a bare repository, you must first ensure that there is no merge conflict - if there is, the push will fail (Reference: book.git-scm.com, "Pushing changes to a public repository"). Merging must therefore be done locally, and then changes fast-forwarded on the bare repository with git-push.

So looking for a right approach.

There isn't anything special about a bare repository, aside from the fact that you should not and can not work out of it. As others have referenced, the gitflow model gives you an idea of a workflow involving several repositories - there are lots of questions on SO asking for git workflow examples and methodologies. Almost every reference (1, Pro Git), (2, book.git-scm.com) uses a bare repository in conjunction with a public or published repository - the linked articles discuss creation and use of bare repositories in detail.

Mattia Righetti
  • 1,265
  • 1
  • 18
  • 31
simont
  • 68,704
  • 18
  • 117
  • 136
  • why do you wish to make a bare repository? I want to have "central" repo to share sw among developers. Some of the are in-house and others are external to company. I want to follow this model http://nvie.com/posts/a-successful-git-branching-model/ – Pepe Feb 17 '12 at 19:23
2

The question is a little unclear with what you're trying to do. Git doesn't enforce a specific workflow model. The idea is to leave it up to you -- The development team. Based on the branch names you posted, it seems to me that you're leaning toward the gitflow model, which is a very successful workflow for many companies and development teams.

When you initially create a repository (if it does not exist on a remote server somewhere), you'd use git init which creates a new repository with a default master branch. You can then add your files using git add and commit: git commit. When you're ready to push to your remote git server (such as github), you'd add the remote git URL using: git remote add origin <url> and push your repository to the server using git push origin master If you already have a remote server you wish to clone the repository from, you'd use git clone <repo url> which pulls down the repository and points you to the default branch (typically master).

Switching branches is useful for when you want to do development on a feature branch and then later merge it in (for example), or when your code is ready for a release, branch into a release branch and eventually merge it into a live/production branch. See the gitflow model for details on doing it that way.

For getting started with git, I recommend reading through the documentation on github, starting with 'beginner'. You can read more about what git is and some basic commands on the A List Apart Get Started with git article as well.

Highway of Life
  • 22,803
  • 16
  • 52
  • 80
  • Yes, I see the "gitflow model". SO question is related to it. I create "bare" repo. I want to have multiple branches on this "bare" repo. So am I able to checkout these branches on the "bare" repo or even doess it make it sense to checkout branches on the bare repo? – Pepe Feb 17 '12 at 08:31
  • So I have bare repo and there is 2 branches: mastrer & develop and I have my local repo with master branch only. I want to push it from my local to bare repo. If I want to push it to develop branch I am getting this: c:\work\Projects\sw_fw01>git push EPO develop error: src refspec develop does not match any. error: failed to push some refs to 'c:\Dropbox\projects\git\sw_fw01.git\' where is the problem? – Pepe Feb 17 '12 at 09:38
  • 2
    @Pepe: `error: src refspec develop does not match any. error: failed to push some refs to 'c:\Dropbox\projects\git\sw_fw01.git\` - this is likely because the `develop` branch does not appear to exist. I'd also advise against using Dropbox as a git repository unless you take extra care; see [here (StackOverflow.com)](http://stackoverflow.com/questions/3632723/git-with-dropbox) for details. – simont Feb 17 '12 at 16:57