1

I am new to a group of researchers, we are using git for version control. We all work on the same machine. There is already a git repository, and everyone else has their own branch. I need to make my own branch named bob.

-bash-4.2$ pwd
/export/home/git/MAS2.5.git
-bash-4.2$ git branch
  alice
* master
  ton
-bash-4.2$ git checkout -b bob ton
fatal: This operation must be run in a work tree

It has been difficult to find a related question since most git guides concern starting from your own fork, or cloning from some remote to local, but this is all on the same machine. For example, this question: fatal: This operation must be run in a work tree seems to have the solution that the user's repository is bare. But this repository is not bare, Alice and Ton have been working for months in here, right?

positive_root
  • 13
  • 1
  • 3
  • 1
    "Bare" in the context of Git does not mean "empty"; it means "contains only Git files rather than the files you work on directly". – jwodder Nov 28 '17 at 01:14
  • 1
    Just clone the repo to another location and then you'll have a working directory. You can then push your branch to the original location using `git push origin your_local_branch`. You should not be working with a bare repo anyway. Go to some other directory `cd /some/other/directory` and clone using `git clone /export/home/git/MAS2.5.git` – francium Nov 28 '17 at 01:16
  • Together these two comments solve my problem. If you'll take another minute to explain, it will increase my understanding. If I have to clone this repository to make a branch, then there will be two repositories, right? That makes sense to me in some remote vs local set up. But this is just one machine so shouldn't there be just one repository? Perhaps I need to think of the multiple users as like different locals accessing a remote? – positive_root Nov 28 '17 at 01:22
  • Possible duplicate of https://stackoverflow.com/questions/9262801/fatal-this-operation-must-be-run-in-a-work-tree – Avinash Nov 28 '17 at 02:11

1 Answers1

1

If I have to clone this repository to make a branch, then there will be two repositories, right? That makes sense to me in some remote vs local set up. But this is just one machine so shouldn't there be just one repository?

You can have any number of clone of a Git repo on a local machine.
The term remote references here the upstream repo to which a repo would push to (or pull from). That repo can be in the next folder on your machine.

So cloning a bare repo will enable you to do your checkout, and then:

cd /export/home/git/
git clone MAS2.5.git MAS2.5
cd MAS2.5
git checkout -b bob ton
git push -u origin bob

(Don't forget the -u: the next push will be a simple git push)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250