Git and Github
An Introduction
An Introduction
git
Image from PhD Comics
Commit = Snapshot of part of your project's state
Centralized (SVN, CVS) vs. Decentralized (Git, hg)
git, noun. Brit.informal. 1. an unpleasant or contemptible person.
$ sudo [yum | apt ] install git
$ git init
# Make your changes
$ git status # or git diff
$ git add <filename>
$ git commit
$ git push origin <branchname>
$ git log
Don't delete the .git files
Avoid redundant copies of the same work in one revision
Don't commit secrets, and if you do change them. Git never forgets.
http://arstechnica.com/security/2013/01/psa-dont-upload-your-important-passwords-to-github/
First create a git repository!
$ mkdir my_python_app
$ cd my_python_app
$ git init
Git will do a one-time prompt for some basic information and then you have a Git Repository! All code in this code can be tracked by git as a single project.
Create and open a new file script.py
with the following command:
def f(x):
print(x**x)
if __name__ == "__main__":
f(5)
Save this file and leave the text editor and tell git to track this code.
$ git status
$ git add script.py
$ git commit -m "My first git commit!"
$ git status
$ git push origin master
$ git log
Git also allows you to clone
a remote repository to work on another
person's code. It's like downloading the entire project and it's git history.
$ cd ~
$ git clone git@github.com:DevOpsBootcamp/tinsy-flask-app.git
$ cd tinsy-flask-app
$ ls
You have successfully clone a remote repository and can start modifying the other person's code. Changes you make on your local version of this project will not affect the original version you modified (although you can push changes if you are allowed to do so by the original owner!)
Github allows you to 'branch' your codebase. This allows you to make changes on a separate track without modifying the original codebse in the same repository. Branches are preserved when you clone a remote repository.
$ git checkout broken
$ python myapp.py
Now you can see your webapp doesn't work correctly when you try to access it in the browser!
We can manually go in and fix it, or run a command to see what changed between this version and the version in the 'master' branch.
$ git diff master
Pull -> Work -> Add changes -> Commit -> Push
Larger projects have more complex workflows