Anonymous user
Open Source Comes to Campus/Curriculum/Directory: Difference between revisions
Open Source Comes to Campus/Curriculum/Directory (view source)
Revision as of 21:35, 14 July 2015
, 8 years ago→Commit and push
imported>Shauna |
|||
(22 intermediate revisions by one other user not shown) | |||
Line 1:
Hi! This is a guide to help you follow along with the "introduction to git" activity - or, if you're not at an event with a mentor, to do it on your own.
There's [https://github.com/FOSSdirectory/FOSSdirectory.github.io a repository] sitting on [http://en.wikipedia.org/wiki/GitHub Github] which contains a
Let's get started!
= The Activity =
== Visit the project on the web ==
Line 63:
* Undo that change, with your editor, save, and then reload in the browser. Make sure what you see in the browser reflects that change.
<blockquote>Here's a completely optional but neat trick: you can see the changes you've made by typing <code>git diff</code>. If you've fully undone your change, entering <code>git diff</code> should return nothing.</blockquote>
== Add your username to the directory ==▼
The first thing we're going to do is make a simple change: you're going to add your username to the directory page.▼
▲The first thing we're going to do is make a simple change: you're going to add your username to the directory
To do this, open up directory.html. Find the list of links to users. If you're familiar with HTML, it should be easy enough for you to find. If you're not familiar with html, the line you're looking for looks like this:▼
<code><a href="#" class="list-group-item">A person!</a> <!-- Copy this line and add your info. --></code>▼
▲To do this, open up
You want to add two piece of information. First, replace "A person!" with your github username. Then, between the quote marks after "a href", add a link to your website ({yourname}.github.io). ▼
▲
▲You want to add two piece of information. First, replace "A person!" with your
The second thing you're going to do is make your own profile page so that the link you just made goes somewhere! To do this, you'll want to make a copy of the template:
cp template.html profiles/$your-github-username.html
You can then open up the new file and edit it to your heart's content! You can add information about yourself, the projects you want to learn about, the skills you want to contribute, and more.
== Commit and push ==
Line 78 ⟶ 85:
git status
You can
git add
Once you've added the changes, you can "commit" them with a message specifying what you've changed.
git commit -m "I added myself to the directory!"
(What's the difference between add and commit, you might ask? "add" let's you specify which specific files you want to include in a commit. If you want to include all the files you've changed you can smoosh these two steps together with <code>git commit -a -m "I added myself to the directory!"</code>)
Now, publish those changes on Github by typing:
Line 98 ⟶ 107:
== Create pull request ==
Visit your personal fork and click the "Pull requests" button on the right. This will offer you the chance to make a new pull request by clicking on "New pull request". Explain what you did, to make it easier for the repository's maintainer.
Line 108 ⟶ 117:
When your changes are merged into the main project repository, the website will be updated with the merged files.
Sometimes your changes will not show because of caching. To get around this problem, add "
==
Once you've made your changes, you can follow
Congrats! You've made yourself a profile - and successfully used git!
= The Follow Up =
You might say "Wait! I want a recent copy of the directory with all the new profiles people have added. How do I do that?"
=== Setting multiple remotes ===▼
There's totally a way to do it, but it's kind of complicated. If your mind is already full with the above activity, you should take a break, and come back to this later if you want to.
Alright. Ready?
The copy of the repository you have on your computer is called your "local" copy. The copy on Github is a "remote". You can see what remotes are associated with your local repository by typing the command:
Line 127 ⟶ 142:
You should see something like this:
origin https://github.com/$yourusername/$your-repository-name (fetch)
origin https://github.com/$yourusername/$your-repository-name (push)
Line 132 ⟶ 148:
Origin is the default name for your remote repository. The urls you see should correspond to the urls used in the "git clone" command above. Right now your only remote is your personal copy of the repository. That's fine for pushing changes, since you need to go through the personal copy to submit pull requests. But what if you want to get an up to date version of the main repository? To do this, you'll need to add the main repository as a remote.
git remote add $name $url
When you do the "git remote -v" command, you should see that you now have two sets of fetch/push listings.
▲Replace $name with whatever you want to label the remote, and $url with the github url for the main repository.
▲When you do the "git remote -v" command, you should see that you now have two sets of fetch/push listings. To get an updated version of the main repository, you can type:
git fetch $name▼
git merge $name/master▼
To update your remote personal repository, you can type:
Line 155 ⟶ 166:
That's it! You can add as many remotes as you'd like, although for the most part people stick to one or two.
== Pulling from the original repository ==
You want to get the most up to date version of index.html from the original repository. To get an updated version of the main repository, you can type:
▲ git fetch $name
▲ git merge $name/master
In our case, though, this may cause a merge conflict. A merge conflict happens when two people (or the same person, at two different points in time) edit the same part of the same file.
<blockquote>If a merge conflict didn't happen this time, you can force it to happen by checking to see the [https://github.com/FOSSdirectory/FOSSdirectory.github.io/commits/master the most recent change] in the original repository. Then, you can make a random edit on the same line as that change. Make sure to add and commit your change before continuing.</blockquote>
So now there are two different index.htmls, your local copy and the origin. How do you reconcile the two?
[[File:Merge1.png]]▼
== Option A: Discard/keep within files ==
To resolve the conflict, scroll through the document until you find sections with these markings. The "========" line separates the two options that are in conflict. Choose which one you want to keep by deleting the other. Then delete all of the markings. Do this for each conflict and then save and exit the file.▼
You will then need to [[Open_Source_Comes_to_Campus/Curriculum/Directory#Commit_and_push | add and commit]] your changes.
== Option B: Discard/keep whole files ==
Dealing with merge conflicts can get messy, especially when there are a lot of changes and you want to keep things from both versions of the file.
In our case, though, we don't want to take things from each version of the file. We just want to update one file, index.html.
Luckily, there's a way to to this at the file level:
▲This should result in a conflict. There are a number of tools you can use to help visualize merge conflicts. For simple conflicts, though, I like to use a basic editor, such as nano, vim, emacs, or whatever you're most comfortable with. In basic text view, a merge conflict looks like this:
git checkout --theirs index.html
Again, once you have done this you will need to [[Open_Source_Comes_to_Campus/Curriculum/Directory#Commit_and_push | add and commit]] your changes.
▲To resolve the conflict, scroll through the document until you find sections with these markings. The "========" line separates the two options that are in conflict. Choose which one you want to keep by deleting the other. Then delete all of the markings. Do this for each conflict and then save and exit the file.
= Further Study =
There's a lot more we haven't covered - though the above should be more than enough to get you contributing to new projects.
Here are some additional resources for learning about git and Github:
* [http://git-scm.com/ Git manual]
* Atlassian's [https://www.atlassian.com/git/tutorial git tutorials] (I especially recommend the tutorials for [https://www.atlassian.com/git/tutorial/git-branches branching].
* [https://help.github.com/ Github's help section]
* [http://gitimmersion.com/ Git Immersion ] - Covers some of the same stuff this tutorial does, possibly helpful if you're still confused.
* [http://try.github.io/levels/1/challenges/1 Try Git] - More tutorials. :)
|