-2

OK a client of mine is asking me to make changes to his site. I get access to their GIT from their webdev team and I only have a vague idea of what I'm doing. I made some changes, managed to push them then got a mail from him raging saying I'm doing it in the wrong branch and to do it in the "wp" branch instead. But I have no idea how to do this, any ideas?

From the start, I used "git clone" to get the repository. I then edit the file then managed to Google a few commands to get it back .. they are ...

git add file.php
git commit -m 'comments'
git push
David
  • 19,577
  • 28
  • 108
  • 128
Doyley
  • 331
  • 1
  • 4
  • 17
  • 4
    Is there anything wrong with just reading the relevant parts of the [Git reference](http://git-scm.com/docs/)? – lanzz Nov 14 '12 at 13:51
  • 2
    There's also a pretty good chapter on branches in [Pro Git](http://git-scm.com/book/en/Git-Branching). If say which source control software you're more familiar with, you're more likely to get *git for X users* links and such. And for the love of all that is good, learn to use google, searching for "git branching", the **very first result** links you to he same chapter of Pro Git that I linked to. – Roman Nov 14 '12 at 13:53
  • Well I'm normally the first person to say "use google" but I've been searching for about 2 hours and nothing I'm trying is working so there's something I'm missing, hence my post. So I posted here, but no worries, I'll keep searching. – Doyley Nov 14 '12 at 14:20
  • http://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide – Gabriel.Massana Mar 17 '14 at 14:14

2 Answers2

4

Although saying "just google it" is somewhat emotionally satisfying, in the end, not particularly helpful.

As I mentioned in the comment the chapter in branching is quite good and does a much better job of explaining git branching than I can here. Robodo also gave the correct answer, that is how you would switch to the wp branch in order to work on it.

It's likely that you got an email saying "you're doing it wrong" because they use a workflow where master branch represents stable deploy-able code (an example of such workflow here). Thus committing stuff directly to master is frowned upon. You should find out what workflow they use and try to follow it as well.

When you run the clone command, get a full copy of the remote repository with all of the branches. You can view all of the branches that are available by running

git branch --all

for me, local branches are white, remote branches are red, and currently checked out branch is green.

Remote branches?

Remote branches are references to the state of branches on your remote repositories. They’re local branches that you can’t move; they’re moved automatically whenever you do any network communication. Remote branches act as bookmarks to remind you where the branches on your remote repositories were the last time you connected to them.

In order to work on a remote branch you create a local branch that tracks the remote branch and commit to that. That may sound kind of strange, but it's really just one command

git checkout -t origin/wp

Once local branches have been created you can switch between them using

git checkout <branch name>

What your workflow will likely end up being is something like this

git clone <url>         
git checkout -t origin/wp               // create tracking branch
git checkout -b <branch name>           // branch for feature you plan to work on
    ... work work work ...
git add <files as needed>               // you can commit locally as much as you'd like
git commit                              // no one will see it until you push
    ... when work is done ...
git checkout wp                         // switch to branch you will merge into
git pull                                // make sure it's up to date with remote code
git merge <branch you were working on>  // merge your changes into wp branch and resolve
                                        // merge conflicts, if there are any
git push                                // publish your changes to remote repository

There are some passionate debates about the merge vs rebase workflows. If your client has a preference, go with it. If they don't, read arguments from both sides, see which one you like better and use it.

Community
  • 1
  • 1
Roman
  • 19,581
  • 6
  • 68
  • 84
  • Don't forget to mark your questions as answered or people will likely stop trying to help. – Roman Nov 29 '12 at 19:29
1

first checkout the branch you need to work on:

get checkout wp

then do you commits and pushes...

robodo
  • 430
  • 3
  • 8
  • This only works if the original poster has a local branch of the remote `wp` branch. If he just cloned, he probably only has a local `master` branch, and so he would need to make a local `wp` branch with `git checkout -b wp remote/wp`. –  Jul 08 '13 at 00:38