Skywalker
Skywalker

Reputation: 5194

Git - managing multiple branches

I have an app deployed on heroku. I've connected my GitHub account to heroku so if I push anything to the master branch it is automatically deployed on heroku and made available to the customer.

To improve this process I've created a development branch where I push all my code while I'm developing and testing out my code. Once that code is ready I want to push it to the master branch to be deployed on heroku.

What I did:

Create Branch

git branch development

Access Development Branch

git checkout development

Pushed Changes to Development Branch

git add .
git commit -am "did something"
git push -u origin development

All of this worked.

My Issue:

I can't figure out the correct process of and how to do the following, from the console:

  1. Pushes changes from development to master branch so say they are equal
  2. Do I need to create a new branch every time I am developing or can I keep reusing the development branch?

Upvotes: 1

Views: 964

Answers (3)

tschoppi
tschoppi

Reputation: 479

You have two issues:

  1. Updating the master branch from the development branch, and
  2. deciding on the general workflow.

Updating master branch

The easiest way to keep your master in sync with the development branch is to locally merge in the development branch and then push the updated master to your GitHub repository:

git checkout master
git merge development
git push origin master

If there was no work done on the master branch directly (as you allude to in your question) the merge should be fast-forward.

You can then check out the development branch again and continue working:

git checkout development

All in all, the graph of this procedure would follow something like this:

-- A -- B -- C          merge       -- A -- B -- C
   |         |         ------->                  |
 master   development                         master, development

Now, onto the more trickier part:

Choosing your workflow

There are countless ways of managing your branches, and there is no canonical one-for-all solution that works for projects of all scales and complexities. That is the power of such a flexible system such as git, but at the same time a small drawback, because which system should you choose?

I would recommend to look at some articles and blog posts on git workflows and then choose one that suits you. If the boundary conditions of your project change, you can always reassess and change the git workflow for that project as you see fit.

Do I need to create a new branch every time I am developing or can I keep reusing the development branch?

With the procedure outlined above, you can continue working on your development branch without any extra steps.

Upvotes: 1

Alexandre Thyvador
Alexandre Thyvador

Reputation: 364

  1. You can either merge your development branch into master or rebase master on your development branch. Some people think that one solution is better that the other, but that's up to you. Here is good explanations about the differences.

  2. This question is really about the workflow. The only rule is that all the people who are working on that git repo agree about what they will do. So If you are alone you can do as you want. But once again some people will tell that you must create new branches for each feature, and opnce again that's up to you.

  3. I would advise you to use some GUI client for Git. There are among others SourceTree, GitKraken or GitHub Desktop. I'm currently using GitKraken, and it allow to handle a git flow pretty easily.

Upvotes: 0

Nolyurn
Nolyurn

Reputation: 608

I recommend you to take a time to watch some git workflow video, you should create a branch for every new functionality, in a real project a branch should not stay open for more than 2 days to avoid merge problem.

Use git merge to import changes from branch to master https://git-scm.com/docs/git-merge

Upvotes: 0

Related Questions