Reputation: 7519
I am taking an online class from Coursera. This is my first experience with git (I usually use SVN) and I am having some issues.
The programming assignments for the class are in a github repository with structure.
class/assignments/assignment1
class/assignments/assignment2
...
The assignmentsX folder contains a skeleton that the student modifies and submits for grading. When the class first start there may be only assignment1, and then assignment2 is added, and then assignment3, .... However, it is possible after assignment1 is added the contents are updated, and the student will have local changes that they do not want to lose. Obviously, students never check in their changes to master GitHub repository. Given this structure I have the following questions:
How can I keep my local copy of assignmentX in sync with the changes the instructor might make without losing my changes. I tried merging but that has not worked to well for me. Maybe my SVN background is getting in the way.
What is the best way to pull down the additional assignments as they are added. I tried using Fetch, but that did not pull the new folders.
Upvotes: 1
Views: 81
Reputation: 15775
The git pull
operation will do a fetch and merge for you, if your local brach is tracking a remote branch. Otherwise nothing will be merged. If you wish to keep your changes completely separate and not merge with the instructor, just do a fetch. The instructors additions/changes will not be merged into your local brach(es). If you wish to examine what the instructor has provided, you can either checkout a new branch based upon the update from the instructor:
git checkout -b new_local_branch remotes/origin/instructor_branch
or you could even check out your local copy of the instructor's branch as a detached head (you cannot commit to it):
git checkout remotes/origin/instructor_branch
Upvotes: 0
Reputation: 2678
1.How can I keep my local copy of assignmentX in sync with the changes the instructor might make without losing my changes. I tried merging but that has not worked to well for me. Maybe my SVN background is getting in the way.
You will need to do a pull
to get the remote changes in your repository. Either the professor will need to tell you when he/she makes changes, or you will need to check yourself if their are changes.
If the changes are possibly conflicting with your local changes, then I suggest creating a branch in your local repository for your changes. This way you never have to worry about merge conflicts. Branching is a huge deal in git, which is a big difference from SVN. I highly recommend you learn how to use them (they're super easy)
2.What is the best way to pull down the additional assignments as they are added. I tried using Fetch, but that did not pull the new folders.
Fetch pulls in the changes, but does not merge them. So, you either have to fetch
then merge
, or just pull
, which does both at once.
Upvotes: 1
Reputation: 239290
I tried merging but that has not worked to well for me.
That's how. You need to fetch the remote changes, and the merge them into your local branches. You can do both steps at once with git pull
, which fetches and then merges whichever branch (if any) your current branch is setup to track.
What is the best way to pull down the additional assignments as they are added. I tried using Fetch, but that did not pull the new folders.
git fetch
effectively makes your repository aware of changes (specifically, new commits, branches and tags) in the remote repository. It doesn't actually apply those changes to your own branch. You need to merge
for that to happen.
Upvotes: 0