简体   繁体   中英

How to get new files on a GitHub master repo

I'm currently in a course where the professor intermittently releases assignments on a public repo. I have this repo cloned on my computer, but I don't know how to go about getting the newly released assignments.

Essentially, I want to pull the new files without deleting my work on the old files which I have edited. Do I create a fork? If so, how do I pull changes from upstream but also keep my changes? How do I resolve the conflicts that will occur when my versions of assignments have been edited? Etc.

Any help is greatly appreciated because, as of now, I've just been moving all of my files and then completely re-downloading the updated repo.

Also, I'm using GitHub desktop

I'm unfamiliar with GitHub Desktop, but hopefully there are simple equivalents in the GUI for these commands. If not, you can try with a backup branch in Git Bash (the command line).

First, stage and commit your changes by doing git add file1 file2 etc. followed by git commit -m "change x"

Then, here are a few possible options to update your current branch:

  • git pull origin master will first fetch the content from the remote and then merge it to your current branch. If you end up with merge conflicts, git will tell you how to proceed. You can resolve conflicts in your editor or GitHub Desktop. For this reason, you may end up with a merge commit.
  • git pull --ff-only will do the above, but it's safer in that it won't create a merge commit. It only updates your local master if the history is linear and it can be fast-forwarded (hence the ff-only).
  • You can also try rebasing to update your branch, which will replay your changes on top of the master history. This makes your commits linear and thus very neat, but remember that you should not rebase public history (eg if you're working with someone else on a branch). Didn't go into too much detail about this because I think it may be a little overkill if you don't care about commit history.

When in doubt, create a backup branch of your current branch with git checkout -b my-backup before trying anything :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM