Avatar
Ba
Dùng Git để phối hợp làm 1 dự án bất kỳ

Cách sử dụng Github để phối hợp làm một dự án cụ thể


Bài viết này dùng tiếng Anh vì được trích xuất từ lớp học AI.

Development Process

1. Clone the project

    git clone ${project-name}

Example:

    git clone https://github.com/bangoc123/protonx-development-process.git

2. Develop a new feature

2.1. Create new branch

    git checkout -b ${branch-name}

Example: You want to build a feature called name build-model

    git checkout -b build-model

You can see all the process via the app called: SourceTree

2.2. Create an init empty commit

    git commit --allow-empty -m 'Empty initial commit'

2.3. Push this commit

    git push origin ${branch-name}

Example:

    git push origin build-model

2.4. Make pull request

Create Pull Request

These some tags you can use to indicate the object/status of your work

  • development (Feature)
  • bug
  • documentation
  • enhancement (improving existing features)
  • done (finished)
  • in progress (not done)

These tags denpend on your team. Make sure it easy to follow.

The result:

Now you can work on this branch and push code until the feature is completed.

This is the tracking system of Git.

Here are some stages you need to know about the git tracking system.

    git add ${file_name_1} ${file_name_2}

means that you select some of your files for pushing online.

    git add .

means that you choose all the tracking files.

    git commit -m "Message"

means you move your code from editable status to ready-to-deploy status.

    git push origin ${branch-name}

means you push your code to the online branch on Github.

2.5. Review progress

At least one reviewer (Perfectly 2) will review your code and make conversation with you when they think you need to update the feature.

From the reviewer's side, they will skim your code and give comments.

The reviewer requires you to update the features.

Then you continue to update your code until the conversation is resolved.

After few loops, when everything is set ok, the reviewer accepts your work.

Right now, you can merge your code to main branch.

2.6. Doing Rebase and Solving conflicts

When developing a feature's branch, there is a high possibility that the main branch is updated by other members so your code in the current branch is behind the main branch. So you need to update the code from your main branch to the current branch and resolve any conflicts on that branch - (do not do it on the main/master branch). Frequently, the owner of the project will block the main branch updates.

Github will lets you know when there're some conflicts.

Doing Rebase Steps

  • Check out the main/master branch
    git checkout main/master
  • Pull the newest updates

    git pull 
  • Check out the current branch
    git checkout ${branch-name}
  • Do Rebase the main branch to the current branch

That means all the new code from the main branch will be added to your current branch. You can see there are critical problems when the new code is conflicted with your current code. In this case, you need to read all the files which have conflicts and resolve all of them.

If there is some code you do not know, please chat with your member and figure out the code to be kept.

You can see in the HEAD sign is the code from the main and the code under ===== is your current. So if the update is good, remove your code. Otherwise, keep it and announce your members.

Then, use git add to update your resolution.

And use git rebase --continue to continue to rebase progress.

You will see this window when everything is good.

Some explanation should be included in the commit messages if you think there are some important changes after your resolution

Type :q to quit the window.

Everything is set. Use git push -f to update your code on Github. (-f means force)

2.7. Ready to merge

It is green, we always love that. :D

Do merging.

And delete your branch

3. TDD Process (To be updated)