Because they are sooooo weird, I write this document to record every weird problem that I have encountered so far.
- You must execute
fetch
andmerge
first before runningcommit
andpush
, otherwise you can see a conflict, especially when I keep working on the same file. - When there is a conflict, the
merge
command will tell you which of your files are conflicting with the incoming files. - You can resolve the conflicts by choosing a version of code. You can also manually change the code.
- When resolving all conflicts, usually you can execute
git add .
,git commit
andgit push
to upload your files to your origin (your own repo). - If you cannot push, try to push in the terminal by runinng
git push
. You will get the instruction of how to solve the problem. (At this stage, avoid runninggit push -f
to force your push. Otherwise, the problem might persist when you make a pull request to the team repo.) - Remember to run
fetch
andmerge
in advance to avoid this problem. You cal also userebase
instead ofmerge
.
- Register the upstream
- Run
git remote -v
. List the current configured remote repository. - Run
git remote add upstream git@github.com:{team repo}.git
. Specify a new remote upstream repository that will be synced with the fork. - Run
git remote -v
. List the current configured remote repository. - Check this web page.
- Merge changes from upstream:
- Run
git fetch upstream
. Fetch the branches and their respective commits from the upstream repository. - Run
git checkout master
. Enter your fork's local master branch. - Run
git merge upstream/master
. Merge the changes from upstream/master into your local master branch. If your local branch didn't have any unique commits, Git will instead perform a 'fast-forward'. - Check this web page.
- If you push a commit that you did not mean to, you may want to revert a commit.
- First of all, backup your correct files, because the files in your local folder would be entirely rewitten later.
- Run this command:
git revert {id / hash}
to safely undo all the changes that have been made in an unwanted pushed commit. - Becasue the reverted files will be stored in the commit area, you must push everything again to your repo.
- Finally, copy your latest files back to the local github folder.
- Now, you can continue editing your files and upload to your repo again.