Fork/Clone Ch. 01 Intro Assignment
Fork/Clone Ch. 01 Version Control Jedi Training
Fork/Clone Ch. 01 Intro Assignment
Fork/Clone Ch. 01 Version Control Jedi Training
A version control system (VCS) allows you to create your programs and keep track of those changes. A distributed version control system allows a group of people to work on the same project and keep track of everyone's individual changes.
There are many different distributed version control systems, including BitKeeper, Mercurial and Git. Git was developed by Linus Torvalds for use during development of the Linux operating system, and has since become the most widely used distributed version control software.
Git works by tracking a repository, which is simply a folder containing some of your files. The files can be code, images, sound, or anything else. You can change the files and PyCharm will autosave them but when you want to record your changes you record it with a commit. A commit is a checkpoint in the development of a project.
GitHub is an online git repository hosting service that makes it easy to collaborate on a project with other people. GitHub consists of a web portal to your online repos. PyCharm lets you use git with either a graphical user interface (GUI) or command line. In this course, we will just be using the GUI. If you want to be considered a 'legit' coder you may want to learn how to use GIT from the command line. There are many tutorials online but I embedded a particularly good one at the bottom of this page in case you are interested.
GitHub hosts many different repositories for projects, many of them open source. Open source projects are public and make their source code available to anyone, usually free of charge, and many people often contribute modifications and enhancements to the project. Most repositories on GitHub are shared as read-only, meaning others can view and copy the project, but cannot modify it without the approval of the owner or manager.
When someone makes a copy of a shared read-only repository, they create a fork. (Think of a tree in the park: the main trunk is the original repository, and it can split off into another direction at a fork.) That person can then make changes to their copy, and if they change something that they think should be incorporated in the main project, they can make a pull request, asking the project owner to "pull" their changes and merge them into the original code.
Once a repository is forked, it is then cloned to the local computer so the code can be worked on. The cloned repository on the person's computer is called your local repository. The repository from which it was cloned on the GitHub servers is called your remote repository. As changes and commits are made, the local repository is synced with the remote repository to keep the two copies "in sync" with each other.
A repository can also have multiple strands of development going on simultaneously. These are called branches. (Think of a tree in the park again: a trunk or fork of a trunk can split off into multiple branches.) A repository can be forked from another repository, and each repository has a master branch, and can have any number of other branches. Often times there are branches for things like bug fixes, testing, and enhancements. At any time these branches can be merged back into the master branch, just like a fork can be merged back into the master.
Before we learn more about GitHub, we need to set up a few things in PyCharm. These are steps you only have to do once right now at the beginning of this course. Each year we upgrade PyCharm so things below might look different. We will be going through it together in class. Open PyCharm! You will see the following window.
Click "New Project" to bring up the following screen.
Change the name to PythonJedi. This will create the folder that we will use to house all of our programs for this class. Fill out the rest of the Project details.
PyCharm works with many Version Control Systems (VCS). We will be using Git, so we need to enter our GitHub account into PyCharm. Under PyCharm select Settings to see the following window. Under Version Control, select GitHub, add your account and click OK.
Your instructor has created a repository for each chapter in this class on the CSP-UHS organization on GitHub. (https://github.com/CSP-UHS) For each chapter, you need to fork it to your Github account and then clone it to a local repository on your computer. The above diagram represents the overall workflow that we will attempt to learn in this chapter. Below, we will step you through the Ch. 1 Jedi Tasks.
Go to github.com and login to your account.
Switch to your instructor's organizational account (https://github.com/CSP-UHS).
Click on the Ch.01 Version Control Repository, click "Fork" in the upper right corner and then select your Github account.
*There is actually a link directly to each repository for each chapter at the top of the page in python.engineeringu.com
Open PyCharm and open your PythonJedi project.
Go to VCS --- Get from Version Control --- GitHub.
Choose the forked repository on your GitHub account.
Click the folder icon on the right of the Directory box and navigate to your PythonJedi folder on your Desktop. Add a slash and then "Ch01" or something like that to make a folder to hold the cloned repository.
Click Clone
Attach the project to the already opened project.
You now have a "local" repository copy of your "remote" repository which is on GitHub.
Open the Ch01/1.1_Github_VCS.py file in PyCharm
Find where it says your Student #: and on the next line type something like: "This is the master branch". As soon as you start typing the following box MAY appear.
You can click the Remember box if you want to but I like this box to always pop-up, so I left it unchecked. We definitely want to add our files to Git so we can make Version Control changes. Click YES!
Again, if you haven't done so already, after Student #: type something like: "This is the master branch". When we commit the file it will save it and also tag it with a commit description which you can revert back to at any time in the future. You can bring up the Commit Changes dialog box in three ways (#3 is my fave!):
VCS-Commit
Click the green checkmark in the upper right corner
⌘K
You will notice the 1.1_Github_VCS.py file is checked. Click on it to make sure it is high-lighted. Enter your name as the author of the commit and enter a Commit Message. In the Diff section at the bottom you can see your changes from the original. Click Commit.
You should do this often with your work throughout the year. DON'T BE AFRAID TO MAKE COMMITMENTS IN THIS COURSE! (funny, right?)
Many times we would like to build some code and test it out but in case it doesn't work we want to get back to our original file. Some people might do this by duplicating a file and using it to test. If ever it doesn't work you can just reload the original file.
GitHub has a better version control system. It's called making branches. These branches and their commitments are stored in ONE file. Let's make a testing branch of our file for us. There are two ways to open the Branches box:
VCS -- Git -- Branches
Click Master in the very-top left (easiest method)
Under the list of Local Branches you only see master because we haven't created any branches yet. Click +New Branch.
Name the branch something like, "Ch1_testing". You can leave the Checkout branch box checked. This means that you are going to create the branch and then switch to it. Click OK!
You will now see the name of your current branch in the bottom right of the screen. If you click on it you will now see it in the list of "Local Branches".
1.) On this testing branch, change "This is the master branch" to "This is a testing branch". Make a commit ⌘K.
2.) Now add your full name and make another commit ⌘K.
3.) Write a cool fact about yourself and make another commit ⌘K.
Now bring up the Branches box and "Checkout" the master branch as shown. Notice that it will still say "This is the master branch" and none of the commits we just made are on this branch.
4.) On this master branch just type in "Me" for your full name and commit ⌘K.
Go to VCS -- Git -- Show History. A Version Control panel will display at the bottom of your PyCharm window. Click on the Log tab. This will display a branch graph of your main branch and test branches with all of the commits.
Checkout the testing branch again and add a few more comments about yourself, like what you want to do after high school and your favorite thing to do. You can do one commit ⌘K when you are done.
Now, we would like to merge our testing branch back into our main branch. To do this, you always need to be on the branch that you want to merge INTO. Therefore you need to switch to the main branch. Now go to VCS -- git -- Merge Changes. You will see the Current Branch is "Master". For Branches to merge check the box for your "testing branch". Enter a Commit Message and click Merge.
A "Files Merged with Conflicts" box will appear because PyCharm wants you to decide which code is going to override which code. Go ahead and click Merge.
This will bring up a comparison (diff) box which shows the original master branch (middle), the original master branch AFTER the testing branch was created (left) and the testing branch (right). The below image is just an example and it won't look exactly like yours. We want to resolve the conflicts. You can click arrows << to bring in line by line code and then click Apply or you can just click the "Accept Right" button.
Once all of the merge conflicts have been resolved and the Apply button has been clicked, you can again commit the merged file and take a look at the log tab in the Version Control panel. you will see that the two branches have now been merged.
So far, all of our commits have been saved to our "Local" repository which means on our computer. How do we push all of our changes (commits) to our "Remote" repository which is on our account at GitHub.com? It's really easy! Just click ⇧⌘K. Shift-Command-K not only commits but also pushes to your remote repository. We don't really need to push every single commit but you can if you want to. You will see a list of all our commits. Select the "Push" button....or push it! Now if you go check the repository on your GitHub.com account you will see that all of the changes and commits have been pushed there.
For this chapter, I plan to merge everyone's 10 lines of code into the original repository on CSP-UHS. For me to do this, every student will need to submit a pull request when they are ready for me to pull their code. To submit a pull request to your instructor, click on your remote repository and select the "New Pull Request" button.
A "Comparing changes" page will come up, showing if you can merge or if there are some conflicts. If you scroll down on that page you will see a side-by-side comparison of the files. Click "Create pull request".
Write a title for your Pull Request and fill out a description or write some comments to your instructor. You then can click the "Create pull request" button. Your instructor will check your work and if it's correct will pull your code into the master.
On all other chapters, if you want your instructor to check or just take a look at something, please create a Pull Request for it. Because a Pull Request is for an entire Repository, please type the assignment name in the title and write a comment about exactly what you want reviewed. After review, the pull request will be closed and you should be e-mailed a notification with the instructor's comments.
WOW! That was a lot of stuff to learn and we haven't even learned any Python yet. That's OK! Version Control Systems are extremely important to professional programmers everywhere so it's great that you are learning this at so early of an age. Again, if you want to considered a 'super cool legit' coder then you should go ahead and learn GIT from the Terminal command line in PyCharm. It's not actually that difficult. Below, is a great tutorial to help you get started.
You can now begin working on your Ch. 1 Jedi Training and Turtorial Art and submit to Canvas