Tuesday, November 27, 2018

Using git branches

There have been some questions about how to do things with gil now that we switched to gitlab.

Mostly rebase,  and some "oh crap my branch is hosed" moments.

First, whenever you are making a change not matter how big or small you need to make a branch (or at least push to a branch that is not develop, master or a releasex-x-x)

git checkout develop
git pull
git checkout -b xxxx/some-useful-name

where xxxx is feature or bug or nothing.  I am not so sure about the usefulness of grouping the branches as feature or bug right now so bug and feature would be nice but its not worth stressing over.

okay you are commiting new and wonderful changes to the new branch!

git push


This is your branch so you can
git push -f
and make the remote branch look just like your local branch.

As features are added to develop you will want to put those changes into your branch.  The way you do this is with rebase.  Rebase will remove your changes pull the specified branch's changes to your branch the "replay your work on top of" the changes from develop.
 git fetch
 git rebase origin/develop  
 First, rewinding head to replay your work on top of it...  
 Applying: added staged command  


more about rebasing here: git-rebase

Last word of advice.  Make yourself a safety net and try new things with git!

You can make a safety net like this:
 git branch copy-of-my-work  


now if you do a pull and get merges or try a `rebase -i` to squash things, or just want to change the code to something completely crazy you have a back up


you can either work on the copy or use it to restore your branch when everything fails and you wish you never switched to git.


A local copy is great because sometimes while collaborating on a branch, the remote doesn't match up perfectly and 'git pull --rebase` does unexpected things to the local branch.  Having that backup branch is nice because in the worst case you can `git push -f` back to the remote restore order to the universe.

No comments:

Post a Comment