jcadima
5/22/2017 - 12:59 PM

Git branching off master

Git branching off master


https://carl-topham.com/theblog/post/what-git-branching-and-how-do-i-do-branch/

To check your current branch type:
$ git branch

That should come back saying ‘master’. If it’s not master then commit current changes and

$ git checkout master
$ git pull

Git branches can take a slash in the name so a folder like structure is the best way go

$ git branch feature/coolwidget

Now we have created the branch we need to switch to it:

$ git checkout feature/coolwidget

There is a shortcut you can use that creates and then checks out the branch

$ git checkout --b feature/coolwidget

This branch exists entirely on your machine at this point. To make it accessible to other developers you need to add it to the remote git server commonly known as ‘origin’

$ git push -u origin feature/coolwidget


Now you can work on your files and commit them as needed, then push the branch to the origin again. When you do a git push its advisable to specify the branch that should be pushed in case other branches you are working on are not ready to be shared yet

$ git add widget.css
$ git commit -am "Added css file for widget"
$ git push origin feature/coolwidget

For reference if you want to push all local branches that have a remote counterpart you can simply do:

$ git push

One other thing to not when pushing a branch is that you can only push when your local branch is ahead (that is has a more recent commit) that the origin branch. If you get a message about it being rejected then you need to do a git pull first and then retry the git push.