M2014
M2014

Reputation: 1164

Git, can I have a setup without local repo?

Regarding to local repo/remote repo model of Git, I wonder if there is a way to set up Git environment so it does not have(need) a local repo at all? It will help for the case we do not need all the members of the team to get to be familiar with Git's two repo model and we always guarantee the connections to our repo on the server(remote repo).

Upvotes: 0

Views: 109

Answers (1)

LightBender
LightBender

Reputation: 4253

Short answer is, no, it doesn't work like that.

origin/develop is a remote ref, not a branch. Remote references in a local repo are just a note of where each branch was the last time you communicated with that remote. These are read only from a user perspective.

If you attempt to check out origin/develop as you suggest, git will check out the commit that reference points to, but because there is no local branch, the checkout will have a detached head. In order to commit in any meaningful way, you'll need to create a branch. Note you'll get this warning if you attempt this:

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

If you don't get this error you have a local branch in a local origin namespace. I had a co-worker who tried to do this by attempting to create a branch on the remote like this:

# THIS IS NOT GOOD CODE DO NOT USE
git branch origin/branch
# THIS IS NOT GOOD CODE DO NOT USE

Which creates a local branch named origin/branch, not a branch on origin. He just about went crazy because he was updating origin/branch and it wasn't showing up in GitHub.

Upvotes: 3

Related Questions