1

I am really sorry this is such a vague request but I need some git help. I know enough to do something pretty stupid, but not enough to know how to avoid doing something very stupid.

I have a remote git server and a working directory on that server. I just need a 'master' for version 1.0 with a development branch and a 'master' for version 1.1 with it's own development branch. I need to be able to work on these independently. I only want one repository so perhaps there would be a master with a 1.0 branch with its own devel branch and a 1.1 branch with its own devel branch.

I don't mind experimenting, if I have a back-out plan, and don't mind learning the hard way but I'm not the only one who uses this repository and I've been asked to make a version 1.1 workspace for the group and I don't know the best way to do that. I also don't know how to back out of anything dumb that I may have done.

After hours and hours of googling and trying to find git books and cookbooks, nothing I've come across helps me because I don't know how to refer to my remote branch properly, among other things, and there is something fundamental that I'm failing to comprehend. I'm at the point I don't know where else to turn. I've seen many posts that get me close to what I need but I can't get past a few hurdles without being able to refer to my set up since git doesn't click for me, yet, and I can't extrapolate others' recommendations onto mine without asking more specific questions.

Is somebody willing to do a little back and forth question/response session with me to help me understand git's brains and verify my setup?

Here's a bit to get us started:

SERVER$ git branch -r
  origin/devel
  origin/master
SERVER$ git branch -l
* devel
  master
SERVER$ git branch -a
* devel
  master
  remotes/origin/devel
  remotes/origin/master

SERVER$ git remote show origin
* remote origin
  Fetch URL: /git/sold.git
  Push  URL: /git/sold.git
  HEAD branch: master
  Remote branches:
    devel  tracked
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local refs configured for 'git push':
    devel  pushes to devel  (up to date)
    master pushes to master (up to date)

Thanks in advance.

harperville
  • 6,921
  • 8
  • 28
  • 36
  • what's your question? I'm sure you can get help here but it's better if you provide one precise question per post. – CharlesB Sep 24 '12 at 20:16
  • I'd like to make the current codebase a snapshot and create versions 1.1 and 2.0 from it, both of which can be worked on as-needed. Following @dmasi's instructions below, when I try `git checkout master`, I get "fatal: This operation must be run in a work tree`. I'm spending my time now trying to figure out what exactly that is and why I don't have one because the answer appears to be 'clone it locally' or 'define your work-tree'. I don't know how one can clone a repo inside itself (seems counter-intuitive) nor do I know where my work-tree is. Suggestions are most welcomed. – harperville Sep 25 '12 at 14:08
  • One of the many things that trip me up is the wording in the documentation. For example: "A git pull without arguments will in addition merge the remote master branch into the current master branch, if any." Here, we have a "remote master" and a "current master". Is the "current master" the "local master"? When does "current" mean "local" and not "master"? That's why my original question is so vague: I keep getting tripped up at each step of this process. In case you couldn't tell, this is my first time ever using a source control and the lingo/assumptions do not mesh well with my brain. – harperville Sep 25 '12 at 14:16
  • Just to keep you updated on this part of my issue, that error message is caused by a bare repository. When I view my config file on my server, it says: – harperville Sep 25 '12 at 15:09
  • `[core] repositoryformatversion=0 filemode=true bare=true` From what I've read, there are two kinds of repos, `working` and `bare`. From what I've read, "If you are collaborating with a team of developers or you need to work on a project from multiple computers" (http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/) so from this, I *do want* a bare repository, right? – harperville Sep 25 '12 at 15:21

1 Answers1

1

This is only my second post on stackoverflow, I hope it is helpful.

master branches

inside repo switch to master branch

git checkout master

now create a copy of the master branch sitting at tag 1.0

git checkout 1.0
git checkout -b master_1.0

switch back to master branch

git checkout master

now create a copy of the master branch sitting at tag 1.1

git checkout 1.1
git checkout -b master_1.1

dev branches

switch back to master branch

git checkout master

now create a dev branch from master sitting at tag 1.0

git checkout 1.0
git checkout -b dev_1.0

switch back to master branch

git checkout master

now create a dev branch from master sitting at tag 1.1

git checkout 1.1
git checkout -b dev_1.1

if ok push changes to the remote

git push

At this point you would have 6 branches total. Your original master and dev plus the new copies. Development can take place on the newly created branches without impacting master. It may not be conventional to have a tag number in the branch name but it will accomplish the task of communicating quickly the branches origin or purpose. Further you can remove, merge, or re-create the branches easily.

To remove branches

remote - (don't forget the ":")

git push origin :BranchName

local - cannot be on the branch you are trying to delete, -D for un-merged branch

git branch -D BranchName
beenhere4hours
  • 970
  • 9
  • 12
  • Thanks for the walk-through. Your post makes sense but I think my repo is messed up? When I go into my working directory, just for reference, and perform `git branch -a` I get `* devel` ` master` ` remotes/origin/devel` ` remotes/origin/master` Back in my master repo, `git branch -l` returns ` devel` `* master` which is what I'd expect. When I issue `git checkout master`, I get this error: `fatal: This operation must be run in a work tree`. Reviewing this error says "clone it locally" or "tell it work-tree" but why clone it (it's the master repo, isn't it?) and what's my work tree? – harperville Sep 24 '12 at 20:32
  • I wish I could help more, but I haven't encountered that issue before. I did a quick google search for "git fatal: This operation must be run in a work tree". The first 3 search results are from stackoverflow. I quickly reviewed them and there may be more helpful info in those tickets. Best of luck, and please post back your resolution for the working tree issue. I'd like to understand it better as well. – beenhere4hours Sep 25 '12 at 00:17
  • Should I perform these steps in the repo on my server or my local repo? I can't do it on my server because my repo is bare, which according to what I've read, I want a bare repo so I can collaborate with others. If I try `git checkout 1.0` on my local repo, it says `error: pathspec '1.0' did not match any file(s) known to git.` Stuck again. – harperville Sep 25 '12 at 15:23
  • I tried on my local repository, which I think is what you wanted in the first place because the last step says "push to remote". Anyway, I think I'm beginning to understand. Now: `WORKSPACE$ git branch -a dev_1.0 * dev_1.1 devel master master_1.0 master_1.1 remotes/origin/devel remotes/origin/master` but even after a push, on the SERVER, I only see `devel` and `* master`. Why don't I see the branches I just created and pushed *to* the server, *on* the server? – harperville Sep 25 '12 at 17:15
  • If I go to my local machine and clone my repository `git clone me@server:/git/myrepo.git`, then cd into myrepo (locally), shouldn't I be allowed to `git checkout master_1.0`? I get: `local$ git checkout master_1.1 error: pathspec 'master_1.1' did not match any file(s) known to git. local$ git checkout master_1.0 error: pathspec 'master_1.0' did not match any file(s) known to git.` – harperville Sep 25 '12 at 17:19
  • At this point, I'm just having a conversation with myself but perhaps it will help somebody. On the server, I have a 'bare' git repo (bare is a must for collab). In my workspace, I `git checkout master`, then `git checkout -b master_1.0` and that will give me a branch in my workspace. If I do a `git push -u origin master_1.0`, then I will push the branch to the repo and set up tracking info in the remote location. My friend uses "Tower" app and we searched on "git publish" and found this: http://stackoverflow.com/questions/2765421/how-to-push-a-new-local-branch-to-remote-repo-and-track-it-too – harperville Sep 26 '12 at 14:07
  • your response helped get me started. Thanks! – harperville Sep 26 '12 at 16:40
  • Sorry, been out it for a couple days and didn't get to check back in. I never had to start with a bare repo before. But this is my normal list that I have to do when working with repos at my workplace. – beenhere4hours Sep 26 '12 at 17:23
  • **Create A New Branch** `git clone git@yourhostname.com:account_name/repo_name.git` `cd repo_name` `git checkout -b branch_name` `git push origin branch_name` `git checkout master` `git branch -D branch_name` `git checkout branch_name` If you need more help or have questions you we've got email etc. Glad to hear that you figured it out though. – beenhere4hours Sep 26 '12 at 17:28