Lesson 8: Version Control
Homepage | Content | Slides | Video |
Warning
This lesson is under construction. Learn from it at your own risk. If you have any feedback, please fill out our General Feedback Survey.
Homepage | Content | Slides | Video |
Warning
This lesson is under construction. Learn from it at your own risk. If you have any feedback, please fill out our General Feedback Survey.
VCS is how one tracks changes, modifications, and updates to source files over time. Creating a history of changes for a project over time.
Repository: | A project. |
Diff: | Delta between two points in history. |
Commit: | A snapshot of project in time. |
Branch: | Modifications made in parallel with the main project. |
Merge: | Introducing changes from one branch into another. |
Clone: | Downloading a local copy of a project. |
Fork: | A modified version of an existing project. |
"I'm going to work at the designated work-bench. Nobody else can work on this until I'm done."
"I'm going to work over here for a while and tell you about what I did later."
Git is a Free and Open Source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. ( https://git-scm.com )
$ git config --global user.name "My Name"
$ git config --global user.email "myself@gmail.com"
$ git config --global core.editor "nano"
Create a project with Git:
$ mkdir my-project
$ cd my-project # Always run `git init` inside of a project folder!
$ git init # Never inside of your home directory.
Add and commit a file to your project with Git:
$ touch newfile.txt
$ git add newfile.txt
$ git commit # Edit message in Nano, save the file, exit to commit.
To see which files are staged, unstaged, or untracked:
$ git status
To look through your repository history:
$ git log
To create and checkout a branch:
#Note the `*` which indicates the current branch
$ git checkout -b "new-branch"
$ git branch
master
* new-branch
Checkout a new feature branch on your repository.
$ git checkout -b "add-awesome-feature"
Create/Edit files on the new branch.
$ echo "Some awesome text" > awesomefile.txt $ git status # On branch add-awesome-feature # Untracked files: ... # awesomefile.txt ... $ git add awesomefile.txt $ git commit -m "Short awesome commit message"
View the diff between the two.
$ git diff master diff --git a/awesomefile.txt b/awesomefile.txt new file mode 100644 index 0000000..08cec7f --- /dev/null +++ b/awesomefile.txt @@ -0,0 +1 @@ +Some awesome text
Locally merge the changes from your new branch into Master.
$ git checkout master $ git merge add-awesome-feature Updating 459de26..5c4ca48 Fast-forward awesomefile.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 awesomefile.txt
Everybody uses VCS differently. Choose the workflow that works best for everybody involved.
To contribute to someone else's repository you first need to clone the repo.
$ cd /path/to/my/projects
$ git clone <some git url>
$ cd <new repo directory>
$ ls
Once you clone a repository you can make as many local changes as you want without affecting the original (central) copy. You can experiment and work without the original owner even knowing what you're doing!
$ cd ~
$ git clone https://github.com/DevOpsBootcamp/tinsy-flask-app.git
$ cd tinsy-flask-app
See http://git.io/vcVmB for more details about the tinsy-flask-app repository.
#Setup python virtual environment
$ virtualenv venv
$ source venv/bin/activate
(venv) $ pip install -r requirements.txt
#Run server
(venv) $ python script.py
#When finished, deactivate virtual environment
(venv) $ deactivate
$
Now if you go to dobc-shell.osuosl.org:<http port> in your web-browser to see a live version of the app!
Your <http port> is the same as your SSH port, but the first 2 numbers are changed from 33 to 34. For example, 33005 -> 34005