Git workflow for multiple feature branch - github

Our current stash repository has a Master and Develop branch.
Anytime if a developer is working on a story a developer creates a branch and once the coding is done a pull request is raised to merge to develop.
So far it has been good but when two developers are working on different feature branches on a same Repository if a developer merges his changes to develop and other one is still working on, there are issues like merge conflicts and we don't want the two different feature branches to be released together.
I know this is not an issue but we want to avoid release multiple feature branches at a time.
Any thoughts on this on what are the best practices.

I would suggest to create tags after you have merge to "develop" branch. There is no harm if you wish to release code from "master" branch using tags as well.
Honestly speaking there aren't any hard lines drawn on how you wish to release your code from Git hosted repos?
You may like to follow this sequence
rebase the feature brnach of second dev from develop branch to get changes of dev1 and avoid merge conflicts
git checkout feature_branch2
git rebase develop
merge feature-branch2 to develop branch
git checkout develop
git merge feature_branch2
tag the version you wish to release
git checkout provide_version_you_wish_to_release
git tag tag_name

The best practice is that the 2nd developer should first rebase his feature branch from "develop" branch and then merge his changes back to "develop" branch by creating a pull request.
If you don't wish to release changes from two feature branches simultaneously, you can create tags on the "develop" branch after a merge is successful and release code using these tags.
Hope this helps!

Related

Lock/Unlock a github branch

How can I lock a github develop branch so that no one can merge PR (even if PR approved) until I unlock the branch? This is needed because I want to create a release branch, out of develop and restrict unintended merge until branch out. I went through branch protection rules and it does not serve my purpose i.e. there is no option that says lock/unlock a branch.
Explanation:
I have a develop branch and developers can create feature branches from develop branch and raise PRs, and once PRs get reviewed and get approval, developers can merge their PRs to develop. Now, I want to create a release branch from develop so I want to restrict all the developers to be able to merge their PRs to develop branch even if PRs got approved. It may take a few days to create a release branch because whatever code I have in develop branch, I want to test and by this testing time, I want to lock the develop branch, so that no one can merge their PRs into develop branch. Once testing successfully done, I will create a release branch from develop and I will then unlock the develop branch, so that, from now on developers can merge their PRs to develop branch.
You can create a branch at any time from any commit, there is no reason to lock an active branch and prevent people from working.
git checkout -b <new branch name> <commit hash>, then git push.
This functionality is not available in git itself. This can be handled by whichever server you use to manage the repo. See Managing a branch protection rule # Github. You can set rules by branch name or pattern and require a PR to merge to that branch. You should also be able to set who can merge and other rules related to branch management.
Since Oct. 2022, you actually can lock a branch:
New Branch Protections: Last Pusher and Locked Branch (Oct. 2022)
Push protection enabled.
This allows for branches to be locked, prohibiting changes.
You can lock a branch allowing you to have a maintenance window and prevent changes, or to protect a fork so it only receives changes from its upstream repository.
To use this feature in a branch protection rule, enable Lock branch.
So:
How can I lock a github develop branch so that no one can merge PR (even if PR approved) until I unlock the branch?
The documentation does include:
You can enable this setting to apply the restrictions to admins and roles with the "bypass branch protections" permission, too.

How to use git flow without using release branch?

There are several branches available in git flow.
such as
feature/
release/
support/
hotfix/
bugfix/
I do not need release/ branch and want to merge staging branch (a development branch) directly to master.
What is the best way to achieve this using git flow?
I think this would be mandatory to make release branch for every release in production or your master branch
So There is no alternative way to do this.
Simply flow is as below:
Work on your feature branch
Finish work and merge your feature branch to staging
Make release branch from staging.
Add version and tag than merge it to master amd staging both.
I think this would be helpful for you.

File conflict resolution in Feature branch

We started using GitHub as Source control in our project recently and we are using Feature branches to work on the features. Once we are done with our development, we merge it to the develop branch using pull request.
During the merge if there are conflicts, we resolve using the web editor. But during this process all the commits done on the file with conflicts get included as a part of the feature branch.
Does anyone know how can i avoid this and make sure the feature branch stays clean?
You should only merge the feature branch into the develop branch (not the other way around). Then resolve the conflicts right there in the develop branch itself.
git checkout develop
git merge feature-branch
resolve conflicts in develop
git push
Note: If you are not too comfortable with the conflict resolution process, then best to create a 'develop-merge' branch, then merge the feature branch into it before creating a cleaner pull request for merging the new 'develop-merge' into 'develop' branch.
This way the develop branch will include all the features at the same time the feature branch won't be convoluted.

Github alternative to force push

We have a dev branch in the team. I want to remove HEAD~9 commit from the dev branch as it was an accidental merge from a feature branch. I don't want to rewrite history as it might lead to problems with working copies of other developers. What other alternatives do I have?
One alternative that I thought is to branch off from dev, remove the commit from that branch, and then merge the new branch to dev. Can this lead to any problem later?

Steps for Git branching & merging for 2 developers

This is the first time I am using Git Hub. So please co-operate with me.
I am working on an iOS project with another developer. Now since we are working on 2 different functionalities, I thought making separate branches for each developer is good way. So my plan in to follow below steps
Create a local branches named functionality1 from the current one using
git checkout -b functionality1
Commit my code in functionality1 branch
Push that branch to the remote using
git push origin functionality1
This will add my branch to remote server. I need branches on remote because I can work from anywhere.
I will merge it in Master branch using
git checkout master
git merge functionality1
Now functionality1 is merged into master branch (provided no conflicts occurred)
Other developer will follow same steps.
We don't want to delete the branches yet.
Now once both branches are merged into master, how can each developer will get the merged code from master branch into their respective branches (functionality1 & functionality2) & then continue on working on same branch (functionality1 & functionality2)?
IMHO you shouldn't unless you really need the new functionality. Because by merging e.g. master back into functionality1 you make it dependend upon the other feature branch. A good read is the gitworkflows(7) man-page.