tags:

views:

789

answers:

6

I'm struggling to understand something about GIT.

We've got a repository with a number of branches in it. I can fetch a local copy of one of those branches (git checkout -b ...), make some changes, then push them back. If I fail to tag the end of the branch, however, how do other users get the head of the branch? WHen they use git checkout to fetch the branch they get the code at the point of the branch -- not the head of that branch.

What am I missing here?

EDIT: I came into this project late and was involved in the CVS to GIT conversion. I am assuming that the FOO_3_4_0001... tags all mark points along the branch kicked off with FOO_3_4_0001_INITIAL. How can I check?

EDIT 2: Thanks to everyone who contributed answers. It turns out that tag FOO_3_4_0001 was not on the 3.4 branch and that's what I was missing all along. I have already arranged the lynching party.

+2  A: 

It sounds like you're doing the right thing. The name of a branch is simply a pointer to the latest commit on the branch. Are you sure you're comming and pushing the changes back to the repo that everyone is pulling from? When you commit, you're only committing to your local repo, so to get changes, collaborations must either (a) pull from your local repo, or (b) pull from some other accessible repo to which you have pushed your changes using git push.

mipadi
+2  A: 

They can just pull from the remote repository to get the HEAD of the remote branch.

$ git remote update
$ git checkout <branch_name>
$ git pull origin <branch_name>
$ <edit> ...
$ git commit
$ git push origin <branch_name>

I have assumed the name of the remote repository as origin here, you can substitute it with the actual name.

Baishampayan Ghose
A: 

Ok, more info for @Dustin and @mipadi.

When I run git branch -r, I see:

16:12:02 (1) foo $ git branch -r
  origin/FOO_3_3_0001_BUILT_VF_BRANCH
  origin/FOO_3_4_0001_INITIAL
  origin/FOO_3_5_0000_RC5
  origin/FOO_3_5_0001_BRANCH
  origin/HEAD
  origin/master
  origin/origin
16:12:05 (1) foo $

And if I look at the list of tags, I see, among other things:

16:12:05 (1) foo $ git tag -l
FOO_3_4_0000_RC1
FOO_3_4_0000_RC2
FOO_3_4_0000_RC2b
FOO_3_4_0000_RC3
FOO_3_4_0000_RC4
FOO_3_4_0000_RC4b
FOO_3_4_0000_RC5
FOO_3_4_0000_RELEASE
FOO_3_4_0000_TC1
FOO_3_4_0000_TC2
FOO_3_4_0001_RC2
FOO_3_4_0001_RC3
FOO_3_4_0001_RC4
FOO_3_4_0001_RC5
FOO_3_4_0001_RC5a
FOO_3_4_0001_TC1
16:14:33 (1) foo $

The challenge I have is knowing what the latest code on the FOO_3_4_0001_INITIAL branch is.

Now in this instance I happen to know that it's FOO_3_4_0001_RC5a, but if I don't (as will sometimes be the case for some of our developers) how do I check out the origin_FOO_3_4_0001_INITIAL branch know that I've got the very latest code on that branch?

Andrew
A: 

@ghoseb, didn't work. I tried this:

16:19:29 (1) foo $ git checkout --track -b FOO_3_4_0001_INITIAL origin/FOO_3_4_0001_INITIAL
Branch FOO_3_4_0001_INITIAL set up to track remote branch refs/remotes/origin/FOO_3_4_0001_INITIAL.
Switched to a new branch "FOO_3_4_0001_INITIAL"
16:19:36 (1) foo $ git branch
* FOO_3_4_0001_INITIAL
  master
16:19:39 (1) foo $ git pull
remote: Counting objects: 68, done.
remote: Compressing objects: 100remote: % (59/59), done.
remote: Total 61 (delta 18), reused 0 (delta 0)
Unpacking objects: 100% (61/61), done.
From ssh://***
   f0c5a5f..99f6c1e  master     -> origin/master
Already up-to-date.
16:19:42 (1) foo $

At this point I checked for the change I made on this branch and it's not there. If I check out the code tagged FOO_3_4_0001_RC5a my change is there.

Andrew
A: 

Just to make sure we're not overlooking the obvious:

When you make changes, do you then commit them before pushing them back? Git branches point to the latest commit on the branch, so if the changes haven't been commited, then the branch will still point to the branch point, which is what you said is happening.

Paul
+1  A: 

Git clone, pull and fetch are working with the entire repository tree. The branches are just tags inside your local repository.

When you have done a clone you have a copy of the remote repository in the origin. You can access this by checking it out locally.

git co -b origin_local_master origin

This creates a local editable branch of the origin master.

But you can also access the branches inside this repository.

git co -b origin_local_dev origin/dev

This creates a local editable branch of the origin branch dev.

andersjanmyr