- Introduction
- Part 1: First Create a Github Account
- Part 2: Connect it to your Repl.it
- Part 3: Update the Repl.it Github Authorization
- Part 4: Review your changes
- Part 5: Commit & Push Your Code
- Congratulations!
Version control refers to a system for keeping track of and managing
changes to a set of files. The most popular version control system today
is git, which is what we will be using.
Version control can be used for any text-based files (school work, essays, books, manuals) but in software we're tracking changes to code and we refer to the group of source code files for any particular project as a codebase. The set of version control data for a codebase or other group of of files is called a repository or repo.
Version control can take a bit of getting used to, but it is one of those life-changing tools that you'll wonder how you ever lived without. Some of the benefits include:
- Keep a remote backup of all of your work.
- Easily see what changes you have made since you were last working on a file.
- Review an older version of your work, or revert back to it.
Github is a service that provides hosting for git repos. Repl.it has an integration with Github that tucks away a lot of the complexity behind a web interface.
- Create an account on Github.com or sign into your existing account.
-
Open your your Repl.it repl.
-
On the left side-nav click the second icon down:
Version Control. -
At the top of the new left-most pane, click the button that says Connect to...
-
It will ask you to Connect to Github. Click the button that says Connect Repl.it to your GitHubAccount
-
A new page will appear titled Install & Authorize Repl.it Online IDE. Click Save.
-
The new window will close and you'll be back at your repl. Click the Connect to... button again.
-
A dialog will appear titled Create a new GitHub repository. Choose a repo name (perhaps "python-class"?) and click Create GitHub repository.
When you authorized Repl.it for Github, you gave it blanket access to all current and future repos. Now that the repo is created, you can change the settings so that Repl.it only has access to that repo.
(You can skip this step if you don't care.)
-
Go to github.com
-
In the top right corner, click your avatar to bring up the user menu.
-
Click the Settings link.
-
On the left side, click the Applications link.
-
Under Installed Github Apps you should see Repl.it Online IDE.. Click the Configure button.
-
Under Repository Access, select the radio button next to Only select repositories.
-
Click the Select repositories drop-down. Click your newly created repository.
-
Click the Save button.
The web interface does not include any features to review your changes, so we'll have to use the command line.
(This gives you a chance to get a feel for the benefits of using version control. But you can skip it for now if you'd prefer.)
The git status tool shows you a list of files that have been changed since
your last commit.
In the right-most Console pane, type:
> git statusYou will see a list of the files that have been changed since your last commit. It will look something like this.
> git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: main.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
.replit
no changes added to commit (use "git add" and/or "git commit -a")The git diff tool shows the details of what you have changed.
The diff tool only shows changes to tracked files--ones that have been
previously added to your repository. To make sure that all of your changes show
up in the diff, we'll first need to add them.
In the Console pane type:
> git add .
> git statusYou will now see that all files with changes are listed under "Changes to be committed:"
> git add .
> git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .replit
modified: main.pyWhen a file is staged for commit, that means that it has been chosen to be
included in the commit.
Now you can use the diff tool with the --staged flag to review all of the
changes you've made since your last commit.
In the Console pane type:
> git diff --stagedThis command will show you a diff of your changes--that is, a the chunk of changes from each file that was changed.
> git diff --staged
diff --git a/.replit b/.replit
new file mode 100644
index 0000000..1acc15c
--- /dev/null
+++ b/.replit
@@ -0,0 +1 @@
+run = "python3 main.py"
\ No newline at end of file
diff --git a/main.py b/main.py
index e69de29..051463d 100644
--- a/main.py
+++ b/main.py
@@ -0,0 +1 @@
+print("hello python class!")
\ No newline at end of fileIf you notice anything you want to change before you commit and push you can go
and edit the file then repeat the git add and git diff steps to review it
again.
In git a commit is a record of a set of changes. The repository for your code exists both on repl.it and on github. In order to update the repo on github with your commits on repl.it the changes will be pushed to Github.
-
On the left side-nav, Click the
Version
Control icon again. In the left-most Version Control pane, it should
now display a link to your newly created repository next to the github icon. -
In the text-area that says What did you change? write a brief description of your changes. (If this first commit is a lot of files, you may want to put something like
First push from repl.it. In the future, it's a good idea to commit frequently, ideally at logical stopping points.) -
Click the commit & push button. If all goes well, your new commit will appear under Previous Commits and the commit & push button will dissappear.
You've successfully created a git repository, reviewed your changes, commited them, and pushed them to github!