2.2.8. Revisioning code with Git, GitHub, and Meld¶
This tutorial will teach you how to use Git, GitHub, and Meld to manage code revisions/versions/changes.
Git is a popular software tool that can be used to manage changes to code, including merging changes from multiple developers. Git organizes code into “repositories”. On your machine, each repository corresponds to a directory (and all of its files and subdirectories).
GitHub is a popular website for hosting Git repositories. In particular, GitHub facilities the merging of code changes among multiple developers. GitHub also makes it easy to distribute source code.
Meld is a program for graphically displaying the differences between two text files. Meld is very helpful to understanding how files have been edited.
2.2.8.1. Installing and configuring the required software¶
This tutorial requires git and meld. Execute this command to install these package:
apt-get install git meld libgnome-keyring-dev
Execute these commands to configure Git:
git config --global user.name "John Doe"
git config --global user.email "johndoe@example.com"
cd /usr/share/doc/git/contrib/credential/gnome-keyring
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
Add the following to ~/.gitconfig
:
[diff]
tool = meld
[difftool]
prompt = false
[difftool "meld"]
cmd = meld "$LOCAL" "$REMOTE"
2.2.8.2. Instructions¶
2.2.8.2.1. Create a GitHub account¶
Visit https://github.com, click “Sign up”, and follow the on screen instructions.
2.2.8.2.2. Join the Karr Lab GitHub organization (group)¶
Send your GitHub username to Jonathan so he can add you to our group.
2.2.8.2.3. Create a repository¶
Sign into GitHub
Add a repository at [https://github.com/new](https://github.com/new). Note, our convention is to use
lower_camel_case
package names.
2.2.8.2.4. Clone a repository (download it to your computer)¶
Git repositories are download from GitHub by “cloning” them. Execute the following command to clone the repository for these tutorials:
git clone https://github.com/KarrLab/intro_to_wc_modeling.git
cd intro_to_wc_modeling
This will create a directory with the name “intro_to_wc_modeling”, download all of the files for the repository from GitHub, and save them to the new directory.
2.2.8.2.5. Reviewing the files that have been changed¶
After you have changed one or more files, you can see a list of the files that you have changed, added, or deleted by running git status
. To see the changes made to an individual file execute git difftool path/to/file
.
2.2.8.2.6. Commit changes to a repository¶
After you have changed one or more files, you can commit (save) those changes to the repository.
Select the changes that you would like to commit by executing
git add path/to/file
. Repeat this for each change you would like to commit.Execute
git commit -m "<brief description of the changes>"
2.2.8.2.7. Marking versions with tags¶
You can use tags to mark the version numbers of key revisions. This can be done by running git tag <version_number>
.
2.2.8.2.8. Push your changes to GitHub¶
Once you are ready to share one or more commits with the rest of our lab, you can push them to GitHub by executing git push
. If you also need to push tags, then you will need to run git push --tags
.
2.2.8.2.9. Pull changes from other developers from GitHub¶
To retrieve changes made by other developers, execute git pull
. Note, if you have made changes which conflict with those made by other developers, Git will prompt you to manually review the conflict lines of code.
2.2.8.2.10. Using graphical programs to manage repositories¶
Several graphical programs are also available to manage Git repositories
GitHub Desktop (Windows, Mac)
2.2.8.2.11. Additional Git tutorials¶
There are numerous additional tutorials which cover more advanced concepts such as branching