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
-
Enter your oop folder in terminal by "cd".
-
Use the command to checkout the present branch you are working:
green "main" with a "*" indicates the present branch is main branch, and red branches are remote branches.
-
To create a new branch, use the command to achieve:
use git branch -a
again to list branches, you can see that we have create a branch named "lec-10".
-
To select branch "lec-10", use command:
and now you can see that we are in the branch "lec-10".
-
Now we can git add
, git commit
, and git push
with only the branch "lec-10" being changed
![image](https://private-user-images.githubusercontent.com/160454617/318396362-88e01516-ee76-466c-9b74-9e26c7c365d7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTYzMDgwODYsIm5iZiI6MTcxNjMwNzc4NiwicGF0aCI6Ii8xNjA0NTQ2MTcvMzE4Mzk2MzYyLTg4ZTAxNTE2LWVlNzYtNDY2Yy05Yjc0LTllMjZjN2MzNjVkNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNTIxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDUyMVQxNjA5NDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT00MTExMGIzYjllMTRmZWRhZTYwZGI4OWViOGI2ZDQ1N2ZkNDRlOWVmN2RkNTVmMTkzMjI5MDY5ODlkMTg4MmUzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.Avl6hDR0UKgiokCyyfWdtUmoH3lmDDbkzPdY74GyxlU)
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
don't care about the number of file that has been committed.
-
Go to your forked repo, you should see a huge banner asking you to create a pull request:
![image](https://private-user-images.githubusercontent.com/160454617/318398926-1932af77-cfb0-4450-88eb-2def7876e81a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTYzMDgwODYsIm5iZiI6MTcxNjMwNzc4NiwicGF0aCI6Ii8xNjA0NTQ2MTcvMzE4Mzk4OTI2LTE5MzJhZjc3LWNmYjAtNDQ1MC04OGViLTJkZWY3ODc2ZTgxYS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNTIxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDUyMVQxNjA5NDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kNDA0ZDZiMGYzOWFhZjEwNzYwYzgzOGIxNDEwN2RkNjk4ZDYzMDQ4MzQ0OWVkNGUwYTE3YTFlZDdjN2Y5MDU1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.__blm-oNCKVRuvhDwa2e2aMj1ew5GouLAATXSm6y3Gk)
-
Click create and you can see that your branch in your forked repo is being compared with the main branch of ARG-NCTU.
![image](https://private-user-images.githubusercontent.com/160454617/318399695-b2782334-2474-447f-bd46-edf369d5ad1e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTYzMDgwODYsIm5iZiI6MTcxNjMwNzc4NiwicGF0aCI6Ii8xNjA0NTQ2MTcvMzE4Mzk5Njk1LWIyNzgyMzM0LTI0NzQtNDQ3Zi1iZDQ2LWVkZjM2OWQ1YWQxZS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNTIxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDUyMVQxNjA5NDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT03YzJlMjhhNzgzM2Q2NTYxMTFiZjg5MDY1ZjUzNzc1YjNhM2Q0Y2UxMGU1N2U0MGMzNDExZDE0NDIzYjA2MTc0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.6MYinsodc8hiH6eMTJkATkmPIrP80snp8tsCTOhptxk)
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
- Go to your main branch first with
git checkout main
.
- Uses command
git branch -d BranchName
to delete specific local branch.
![image](https://private-user-images.githubusercontent.com/160454617/318402617-4dee7707-c7d2-4c55-ba5b-6b1a4f08fd9c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTYzMDgwODYsIm5iZiI6MTcxNjMwNzc4NiwicGF0aCI6Ii8xNjA0NTQ2MTcvMzE4NDAyNjE3LTRkZWU3NzA3LWM3ZDItNGM1NS1iYTViLTZiMWE0ZjA4ZmQ5Yy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNTIxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDUyMVQxNjA5NDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zN2I2OTg0ZjcxNzk2YTE5NTFmZThiNWExMTNlNmU4YmIwN2NlNDFjZWYwNTI1YTIwNmJlZDU4N2U1ZjcyYmRmJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.AcASw23fzz4J9QIpHjmfdHjCgM_8DCzaEWrRfXIPpSo)
![image](https://private-user-images.githubusercontent.com/160454617/318402758-980db8b1-b024-4912-9076-bdb4cecf5ba7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTYzMDgwODYsIm5iZiI6MTcxNjMwNzc4NiwicGF0aCI6Ii8xNjA0NTQ2MTcvMzE4NDAyNzU4LTk4MGRiOGIxLWIwMjQtNDkxMi05MDc2LWJkYjRjZWNmNWJhNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNTIxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDUyMVQxNjA5NDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1iMDBmNzEzOGU2YzhlZjc5OTM0YThiOGQ2ZTE0NjVmZDg4NzRiZjhkNmU4NjE2ODE5NTQyOWIzZDM3MzI1MzMxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.sRwsY2ewnQj36N_tWV_NQsIkkFn83f-EkSCBShGtKN0)
You can see that the local branch has been deleted.
Remote branch
- Go to your main branch first with
git checkout main
.
- Uses command
git push origin -d BranchName
to delete specific remote branch.
![image](https://private-user-images.githubusercontent.com/160454617/318403153-f544427c-5924-4bac-afd2-027ae415f1a4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTYzMDgwODYsIm5iZiI6MTcxNjMwNzc4NiwicGF0aCI6Ii8xNjA0NTQ2MTcvMzE4NDAzMTUzLWY1NDQ0MjdjLTU5MjQtNGJhYy1hZmQyLTAy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GZiZjgwY2Y5ZmU1YjRjMTk5MjRkMGExM2I2NjdhOGNjNWEzNWUwODFmY2NlYjkzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.6Dd93ftOF_q-tqd1XKoQ01BRP8PBFmqe8tuqewsixDk)
You can see that the remote branch had been deleted.
Hope these do help you, 椰.