| Objectives |
|---|
| Commit and track your versions of a project. |
| Fork and edit versions of a project. |
| Create branches for your project. |
If you haven't already create a GitHub account.
For any project you should have an editor. I recommend downloading and using Atom. Why? It has good out the of the box hints for projects using Git and is popular.
- Repo or repository
- Local repository
- Remote repository
- Git
- GitHub
- GitHub Desktop
- Terminal
You should begin downloading GitHub desktop.
- Download Github Desktop
- Open GitHub Desktop and continue through it's setup process.
- Connect to GitHub using your Login and Password.
- Configure Git with your email.
- Finish up and skip the tutorial.
Let's download our first project.
Before we download or create any project we should create a folder to help us remember where we have them all.
- Make a folder on your Desktop for all your future projects.
- Call it
my_projects
- Call it
This will just help us stay organized.
Now that we have a place to put our projects we can download an existing one.
- Go to the
pizza projecton GitHub. - Click the green
Clone or downloadbutton in the upper right hand corner. - Select the Download ZIP.
- Move the
pizza-masterfolder from yourDownloadsto yourDesktopfolder calledmy_projects.
Remember moving the project from the Downloads to your Desktop/my_projects folder is just to help you stay organized.
- Open the
my_projectsfolder and locate yourpizza-masterproject. - Drag the
pizza-masterproject to your GitHub Desktop application.
You should be prompted to initialize a new project. This is because downloading the project does not retain any of the Git information. Effectively, this is a new project.
You'll want to edit the pizza-master/README.md file to add your own list of favorite toppings.
You should drag the pizza-master folder to your editor to open it.
You can also open atom add click
File > Open...or on windowsFile > Open Folderand select yourDesktop/my_projects/pizza-masterfolder.
Your README file should look like the following.
README.md
# Learn To Code
## Love For Pizza
My favorite pizza toppings are...
You should edit it by adding your own favorite toppings like the following.
README.md
# Learn To Code
## Love For Pizza
My favorite pizza toppings:
* Cheese
* More Cheese
* Even more cheeseOnce you add your own favorite toppings you should save your changes.
This is a good stopping point to make your first commit.
- Commit: A commit stores the current contents of your project with message describing the changes. The message that goes along with a commit is called a Commit Message.
If you new files to commit in Atom then they will show up as green. It's a nice reminder.
Let's commit the file you edited. Fill out the Summary and Description of the changes then click Commit to master.
A Good commit message summary always starts with a verb describing the change in an imperative form:
Add a project readmeRemove old comments in codeUpdate project dependanciesFix search logic to include cute kittensRefactor legacy search logic
Avoid other verb forms
Removing old commentsUpdated project dependanciesMore fixes to help searching for kittens
Use your message description to explain why you are making the change. Briefly describe what changed also.
A good first commit can read as follows:
- Summary: Add project readme.
- Description: Adds a readme with a list of my favorite pizza toppings.
Now we are ready to sync our changes to our own GitHub accounts.
- Click the
Publishbutton in GitHub Desktop.
- Add a project name and description.
- Then click the publish repository button.
Now you should be able to view your first project on GitHub. If you go to GitHub and look under your repositories tab.
- Open the GitHub Desktop application (if it's not open already).
- Click
File > New Repositoryto create a new repository. - Give it the name
famous-places
-
Make sure you choose 'Local Path' to be your
~/Desktop/my_projectsfolder. This will help you remember where it is latter. -
Open your
famous-placesproject in Atom or your editor of choice by dragging it from yourDesktop/my_projectsfolder to your editor. -
Once it's open you can click create a new file by going to
File > New Fileor hittingCMD + N. -
In the empty file write the following with your favorite places in the world.
# Famous Places
My favorite famous places in the world are the following:
* a place
* another place
* yet another place
- Then save the file by hitting
CMD + sor clickingFile > Saveand saving the file asREADME.md. - Go back to GitHub Desktop and review your changes.
- Write a commit summary and description and commit to master.
- Click publish.
- Give the project a name and description and publish.
- View the project on GitHub and verify it has your favorite changes.
Repeat the process for creating a project from scratch with a theme all your own.
Let's continue learning with our pizza project. We want to update our favorite toppings.
- Go to your
something-about-pizzarepo on GitHub. - Click the
README.mdfile. - Click the pencil icon to edit the file. Change one of your favorite toppings.
- Then commit your changes a message summary and description.
- Go to GitHub Desktop and click
Sync. - You should now see the changes.
Here we are seeing we can make remote changes and sync them with our local repository.
- Open your
pizza-masterproject in Atom or your choice editor. - Open the
README.mdand update your favorite toppings again. - Commit the changes using your GitHub Desktop application with a summary and description.
- Then click sync.
- Go to GitHub and find your
something-about-pizzaproject to verify the changes were synced.
If more than two people are collaborating on a project you can run into a conflict where two people have made changes that conflict.
Let's try to simulate how this can happen.
- Go to GitHub and edit your
something-about-pizzaprojectREADME.mdto say the following:
README.md
I love pizza.
- Commit those changes with a summary and description on GitHub's web editor.
DO NOT SYNC THESE CHANGES
- Go to your
READMElocally for project and change it to the following.
README
I hate pizza.
- Then commit that change using the GitHub Desktop application with a summary and description.
When you click the sync button you'll get a conflict.
Close the warning and now you have to resolve the issue.
Your README should now look like the following:
README
<<<<<<< HEAD
I hate pizza.
=======
I love pizza.
>>>>>>> origin/master
This note that it tells us the first section before the ===== belongs to your local HEAD of changes.
<<<<<<< HEAD
I hate pizza.
=======
Then comes the remote changes someone else synced.
=======
I love pizza.
>>>>>>> origin/master
It is now your job to determine how to resolve these changes. You should delete one of them or try to take some of the changes from the remote.
Let's imagine we somehow hate pizza. Then we should delete origin/master section. So our README just says the following:
README
<<<<<<< HEAD
I hate pizza.
======
But we should remove the extra ===== and <<<< that were helping us see the conflicting lines.
README
I hate pizza.
Now that we edited the file with the conflict we can commit the resolution of the conflict.
-
Go to the GitHub Desktop and create a commit summarizing the conflict resolution.
- Resolve Merge Conflicts
- Resolves README conflicts regarding feelings about pizza.
Once you have committed you should be able to sync your changes.
- Change your
READMElocally to say you love pizza. Commit the changes using GitHub Desktop and sync them to GitHub. Verify the changes were synced by going to GitHub.
Because working together can cause conflicts. Git has a built in branching mechanism that allows you to start making changes on in isolated history of changes called a branch.
Let's create a branch for some changes we want to make with our something-about-pizza project.
Now are changes won't be on the master branch. The master branch is the main/default branch everyone is using as the current state of our project. Everything that goes on the project should be added through a review process using branches and GitHub to merge.
- Update your
READMEto have one more new favorite pizza topping. - Save that change and give it a commit summary and description.
- Then click the publish button.
You should now see an update on GitHub indicating the branch was added.
Click the compare and pull request button. Then give the pull request a title and description.
You should always review your file changes before to spot errors. Create a commit and sync it.
If there aren't any errors click the Create Pull Request button. Once you have an open pull request someone can begin reviewing your changes and click the merge pull request button.
However, you are the only one working on this project, so just leave a comment like LGTM and click merge.
Once you have merged you'll be asked if you want to delete the branch. Click delete branch so you don't have a bunch of branches hanging around.
Now that you have merge your changes from the branch you created you can go ahead and switch back to master.
- Go to
Repository > Show Branchesand select themasterbranch.
However, you won't see the most recent changes so you will need to click the sync button to get them.
We've deleted our branch on GitHub for add-more-toppings. However, you also need to delete your local branch copy for add-more-toppings since we've already merged the changes it had.
- Go to
Repository > Show Branchesand select theadd-more-toppingsbranch. - Then go to
Branch > Delete add-more-toppings
You should now be back sent back to your master branch.
- Create a new branch called
add-more-cheesefrommaster. - Create a new branch called
remove-toppingsfrommaster. - Delete the branch called
add-more-cheese. - Switch to the branch called
remove-toppings. Update theREADMEby removing a favorite topping. Commit the changes and publish the branch.
Forking is a way to create a copy of another repository for your personal use. You aren't allowed to edit another person's repository unless they've explicitly set you up as a contributor. Forking is the best you can do.
-
Go to any repository on GitHub and click the fork button in the upper right hand corner.
- Try forking the pizza repo: pizza repo.
-
You should now see it under the list of repositories for you account.
Cloning is a way for you to copy a repo from GitHub with all the existing Git history. Unlike a download it will not be a fresh repo.
Let's clone your fork of the pizza app for this class:
- Go to GitHub Desktop
- Click
File > Clone Repositoryand type thepizza - Select
Clone pizza - Give it a name and select your
Desktop/my_projectsfolder
You have successfully cloned your first repo.







