| 141 | === Using a branch for development === #branch |
| 142 | |
| 143 | Commonly, you'd use a local branch for development if you want this work isolated, such as when you are making experimental changes or it may take some time complete the work. |
| 144 | |
| 145 | The life cycle for a branch, say "foobar", might look like this: |
| 146 | {{{ |
| 147 | git branch foobar # creates a local branch |
| 148 | git checkout foobar |
| 149 | }}} |
| 150 | |
| 151 | - lots of edits and testing |
| 152 | |
| 153 | {{{ |
| 154 | git commit -m "blah blah" |
| 155 | }}} |
| 156 | |
| 157 | |
| 158 | - more testing and corrections |
| 159 | |
| 160 | {{{ |
| 161 | git commit -a --amend -m "revised blah blah" |
| 162 | }}} |
| 163 | |
| 164 | |
| 165 | - throughout the process, you can 'git checkout master' / 'git checkout foobar' to switch in and out of the branch. |
| 166 | |
| 167 | - if there are upstream changes that need to be reflected in your branch... |
| 168 | |
| 169 | {{{ |
| 170 | git branch --set-upstream-to=origin/master foobar |
| 171 | git pull --rebase |
| 172 | }}} |
| 173 | |
| 174 | |
| 175 | - finally, work is done. Now merge the changes into your local master... |
| 176 | |
| 177 | {{{ |
| 178 | git checkout master |
| 179 | git merge --ff-only foobar |
| 180 | }}} |
| 181 | |
| 182 | - check that only your expected commits are about to be pushed |
| 183 | |
| 184 | {{{ |
| 185 | git log origin/master..foobar |
| 186 | }}} |
| 187 | |
| 188 | |
| 189 | - normal steps to push |
| 190 | |
| 191 | {{{ |
| 192 | git pull --rebase && git push origin master |
| 193 | }}} |
| 194 | |
| 195 | |
| 196 | - if we're done with the branch, nuke it |
| 197 | |
| 198 | {{{ |
| 199 | git branch -d foobar |
| 200 | }}} |