From 521fb3dc5de606114ac5cebbb654336492d7461f Mon Sep 17 00:00:00 2001 From: Cameron McEfee Date: Fri, 25 Feb 2011 13:26:21 -0800 Subject: commit before deleting the 'explain it' styles --- _posts/2011-02-17-fork-a-repo.markdown | 80 +++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 16 deletions(-) (limited to '_posts/2011-02-17-fork-a-repo.markdown') diff --git a/_posts/2011-02-17-fork-a-repo.markdown b/_posts/2011-02-17-fork-a-repo.markdown index 4e8878c..29fd3e4 100644 --- a/_posts/2011-02-17-fork-a-repo.markdown +++ b/_posts/2011-02-17-fork-a-repo.markdown @@ -6,41 +6,39 @@ categories: bootcamp main_category: bootcamp --- -If you’ve found yourself on this page, we’re assuming you’re brand new to Git and GitHub. At some point you may want use another user’s project as the starting point for your own. This is known as "forking." +If you’ve found yourself on this page, we’re assuming you’re brand new to Git and GitHub. At some point you may want use another user’s project as the starting point for your own. This is known as “forking.” ##First: Fork A Repo -For this tutorial, we'll be using the Fork It project. +For this tutorial, we’ll be using the Spoon-Knife project. -1. Fork the “Fork It ” repo +1. Fork the “Spoon-Knife ” repo - To fork this project, click the "Fork" button. + To fork this project, click the “Fork” button. Click “Fork ##Next: Set Up Your Local Repo -You’ve successfully forked the Fork It repo, but so far it only exists on GitHub. To be able to work on the project, you will need to clone it to your local machine. +You’ve successfully forked the Spoon-Knife repo, but so far it only exists on GitHub. To be able to work on the project, you will need to clone it to your local machine. -1. Clone the “Fork It ” project +1. Clone the “Spoon-Knife” project Run the following code:
-	$ git clone git@github.com:octocat/Fork-it.gitClones the linked repo into the current folder
+	$ git clone git@github.com:username/Spoon-Knife.gitClones your copy of the repo into the current folder in terminal
 	
2. Configure remotes - Each repository has a default remote* called `origin`. The origin remote in your new cloned repo points to your fork on GitHub, not the original repo it was forked from. To help you keep track of the original repo, you will add another remote named `upstream`: + Each repo has a default remote called `origin`. A “remote” is a repo stored on another computer, in this case on GitHub's server. The `origin` remote in your local repo points to your fork on GitHub, not the original repo it was forked from. To help you keep track of the original repo, you will add another remote named `upstream`:
-	$ cd Fork-itChanges the active directory in the prompt to the newly cloned "Fork-it" directory
-	$ git remote add upstream git://github.com/octocat/Fork-it.gitCreates a remote called "upstream" and assigns it the original repo URL
-	$ git fetch upstreamPulls in any changes not present in your local repository, but doesn't modify your working files
+	$ cd Spoon-KnifeChanges the active directory in the prompt to the newly cloned "Spoon-Knife" directory
+	$ git remote add upstream git://github.com/octocat/Spoon-Knife.gitAssigns the original repo to a remote called "upstream"
+	$ git fetch upstreamPulls in any changes not present in your local repository, but doesn't modify your working files
 	
- - *A “remote” is a reference to the GitHub URL where your commits are stored. ##Then: More Things You Can Do @@ -51,7 +49,7 @@ Congratulations, you’ve successfully forked a repo, but get a load of thes Once you’ve made some commits to a forked repo and want to push it to your forked project, you do it the same way you would with a regular repo:
-	$ git push origin masterPushes commits to GitHub
+	$ git push origin masterPushes commits to your remote repo stored on GitHub
 	
- Pull in upstream changes @@ -59,10 +57,60 @@ Congratulations, you’ve successfully forked a repo, but get a load of thes If the original repo you forked your project from gets updated, you can add those updates to your fork by running the following code:
-	$ git fetch upstreamFetches any new changes from the original repo
-	$ git merge upstream/masterMerges any changes fetched into your working files
+	$ git fetch upstreamFetches any new changes from the original repo
+	$ git merge upstream/masterMerges any changes fetched into your working files
 	
+ +
+

What is the difference between fetch and pull?

+
+

+ There are two ways to get changes from a remote repo or branch: fetch and pull. While they might seem similar at first, there are distinct differences you should consider. +

+

Pull

+
+					$ git pull upstreamPulls changes from upstream and adds them to the local repo
+				
+

When you use pull, Git tries to automatically do your work for you. It is context sensitive, so Git will apply any pulled changes to the branch you are currently working in. One thing to keep in mind is that pull automatically applies the changes without letting you review them first. If you don't closely manage your branches you may run into frequent conflicts.

+ +

Fetch/Merge

+
+					$ git fetch upstreamFetches any new changes from the original repo
+					$ git merge upstream/masterMerges any changes fetched into your working files
+				
+

When you fetch, Git downloads any changes from the specified branch, but does not apply them to your files. This is very useful if you need to keep your repo up to date but are working on something that might break if your files are updated. To apply the changes, you use merge. This combines the specified branches and prompts you if there are any conflicts.

+
+
+ +- Work with branches + Branching allows you to build new features or test out ideas without putting your main project at risk. A Git branch is a small file that references the commit it was spawned from. This makes Git branches very small and easy to work with. + +
+

How do I use branches?

+
+ +

+ Branches are pretty easy to work with and will save you a lot of headaches, especially when working with multiple people. To create a branch and begin working in it, use the following script: +

+ +
+				$ git branch newbranchCreates a new branch called "newbranch"
+				$ git checkout newbranchMakes "newbranch" the active branch
+			
+ +

Alternatively, you can use the shortcut:

+ +
+				$ git checkout -b newbranchCreates a new branch called "newbranch"
+			
+ +

To switch between branches, use checkout.

+ +
+
+ + - Pull requests If you are hoping to contribute back to the original fork, you can send the original author a [pull request](/pull-requests/). -- cgit v1.3.1