This is my memo after I completely crushed the main branch and re-learned how I could avoid this disaster(the story is here). I hope I can save others from getting same problem as us.
Gitflow
According to the document by Bitbucket, Gitfolw is “an abstract idea of a Git workflow”.
There are mainly three types of branches: main, develop, and features.
The following is the typical usage of their branches.
main
The branch for storing the official history.
develop
The branch for integration of features.
features
Each feature should have their own branch whose parent branch is develop. Features branches are normally named an individual name to identify what feature the branch adds whereas main and develop are always main and develop.
How to push each feature to the develop branch
I would like to show the basic process of pushing a feature branch to the develop branch. The chart below is the overview of the process.
Patten1: No develop branch updates
1. Switch to develop branch
After adding all files and committing the latest change to your feature branch, move to the develop branch.
git switch(or checkout) develop
You can check your current working branch by the command below.
git branch
You are in hello-world branch in this example.
2. Pull latest develop repo from GitHub repo
Pull latest develop repo just for checking if there are any updates or not.
git pull origin develop
If you see the message below, there are no update on develop branch.
3. Push your branch to GitHub repo
// go back your feature branch
git switch(or checkout) your-feature
// push
git push --set-upstream origin hello-world
tip
If it is the first time for your branch to push to GitHub, you can get the command by typing the command below.
git push
Then you will get this message and you can copy the given command.
4. open a pull request
Go to the GitHub repository page and click “Compare & pull request”.
CHANGE THE DESTINATION TO DEVELOP!!!
This is super important because the default destination is the main though the appropriate destination in this case is the develop.
It seems a good convention to use these blue square areas. (I found an example from an open source project)
You will see this screen and done:)
Patten2: There are updates on develop branch
1 and 2 procedures is almost same as Pattern1.
1. Switch to develop branch
After adding all files and committing the latest change to your feature branch, move to the develop branch.
git switch(or checkout) develop
2. Pull latest develop repo from GitHub repo
Pull latest develop repo just for checking if there are any updates or not.
git pull origin develop
If you find there are some updates, you have to merge these changes before you push your feature branch.
3. back to your feature branch
git switch(or checkout) your-feature-branch
4. merge your local develop branch
git merge develop
If you see this message, it’s time to deal with merge conflict. Sometimes you might have to make sure what changes to keep by asking your project leader.
5. Manage the conflict
If you use VS code, you can choose an option and click it.
In this case, I chose “Accept Both Changes”.
Then, commit these changes and push it. The process on the GitHub page is the same as Pattern1.
That’s it! Thanks for reading :)
The original article is here
Top comments (0)