Merge development branch with master
Personally, my approach is similar to yours, with a few more branches and some squashing of commits when they go back to master.
One of my co-workers doesn't like having to switch branches so much and stays on the development branch with something similar to the following all executed from the development branch.
git fetch origin master
git merge master
git push origin development:master
The first line makes sure he has any upstream commits that have been made to master since the last time updated his local repository.
The second pulls those changes (if any) from master into development
The third pushes the development branch (now fully merged with master) up to origin/master.
I may have his basic workflow a little wrong, but that is the main gist of it.
I generally like to merge master
into the development
first so that if there are any conflicts, I can resolve in the development
branch itself and my master
remains clean.
(on branch development)$ git merge master
(resolve any merge conflicts if there are any)
git checkout master
git merge development (there won't be any conflicts now)
There isn't much of a difference in the two approaches, but I have noticed sometimes that I don't want to merge the branch into master
yet, after merging them, or that there is still more work to be done before these can be merged, so I tend to leave master
untouched until final stuff.
EDIT: From comments
If you want to keep track of who did the merge and when, you can use --no-ff
flag while merging to do so. This is generally useful only when merging development
into the master
(last step), because you might need to merge master
into development
(first step) multiple times in your workflow, and creating a commit node for these might not be very useful.
git merge --no-ff development
Explanation from the bottom for ones who came here without any knowledge of branches.
Basic main/master branch development logic is: You work only on another branches, so you use main/master branch only to merge with another branch which is ready for merging.
You begin to create a new branch in this way:
- Clone repository in your local dir (or create a new repository):
$ cd /var/www
$ git clone [email protected]:user_name/repository_name.git
- Create a new branch. It will contain the latest files of your master branch repository
$ git branch new_branch
- Change your current git branch to the new_branch
$ git checkout new_branch
- Do coding, commits, as usual…
$ git add .
$ git commit -m “Initial commit”
$ git push # pushes commits only to “new_branch”
- When job is finished on this branch, merge with “master” branch:
$ git merge master
$ git checkout master # goes to master branch
$ git merge development # merges files in localhost. Master shouldn’t have any commits ahead, otherwise there will be a need for pull and merging code by hands!
$ git push # pushes all “new_branch” commits to both branches - “master” and “new_branch”
I also recommend using the Sourcetree App to see visual tree of changes and branches.