Skip to content

Create Pull Requests with Specific Changes of the Repo / Solved #111

@cookieeikooc

Description

@cookieeikooc

Note: I asked professor for help and he asked me to create an Issue to give more detail of the problem I encountered, but luckily I found the solution, hope this content can help you guys 🫶.

Issue

If the previous commit isn't approved and merged by the repo owner, the next time I commit some changes, the changes will belongs to the previous pull request. To make the pull request commit details less messy, I would have to delete the previous commits and lost all my previous changes, and I wouldn't be able to create a new pull request of the changes on my forked repo without closing my pull request.

Solution

Introduction to Branches

You can treat branches as different versions of your repo with specific changes. It's useful since that you can make changes of the branch, test the branch, and commit without affecting the master branch (or mostly named as "main") of your repo.

What Can We Do with Branches?

Imagine that you and your teammates are working on a project, but each of them have their own changes of the code, to avoid conflicts, you can create (or ask them to) branches for each member of the group, and they commit changes on their branches, creating pull requests which compared their own branches with main branch, and the owner can decide whether or not to merge the commits.

For our OOP lecture, it can solve the issue I'd encountered. By creating branches, I can create a pull request that only has specific changes so that I don't have to make sure that all my previous commits are valid and approved by TAs so that TAs can merge my new commits into the OOP repo owned by our professor without the affect of my previous pull requests.

How to Use Branches

Create a Branch & Create Pull Request Across Specific Remote Branch

  1. Enter your oop folder in terminal by "cd".

  2. Use the command to checkout the present branch you are working:

    git branch -a
    
    image green "main" with a "*" indicates the present branch is main branch, and red branches are remote branches.
  3. To create a new branch, use the command to achieve:

    git branch BranchName
    
    image

    use git branch -a again to list branches, you can see that we have create a branch named "lec-10".

  4. To select branch "lec-10", use command:

    git checkout BranchName
    
    image and now you can see that we are in the branch "lec-10".
  5. Now we can git add, git commit, and git push with only the branch "lec-10" being changed
    image
    note that when you execute git push, making sure you use this commend to make your branch visible online (set as a remote ranch):

    git push --set-upstream origin BranchName
    
    image

    don't care about the number of file that has been committed.

  6. Go to your forked repo, you should see a huge banner asking you to create a pull request:
    image

  7. Click create and you can see that your branch in your forked repo is being compared with the main branch of ARG-NCTU.
    image
    and you can create a pull request under your own control.

To create and checkout the branch at the same time, you can use git checkout -b BranchName

By doing so, you can keep your main branch synced with ARG-NCTU, and only make changes in a branch, keeping your changes organized.

Delete a Branch

Local branch

  1. Go to your main branch first with git checkout main.
  2. Uses command git branch -d BranchName to delete specific local branch.
    image
    image
    You can see that the local branch has been deleted.

Remote branch

  1. Go to your main branch first with git checkout main.
  2. Uses command git push origin -d BranchName to delete specific remote branch.
    image
    image
    You can see that the remote branch had been deleted.

Hope these do help you, 椰.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions