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.
220.127.116.11. 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 "firstname.lastname@example.org" 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
[diff] tool = meld [difftool] prompt = false [difftool "meld"] cmd = meld "$LOCAL" "$REMOTE"
18.104.22.168.1. Create a GitHub account¶
Visit https://github.com, click “Sign up”, and follow the on screen instructions.
22.214.171.124.2. Join the Karr Lab GitHub organization (group)¶
Send your GitHub username to Jonathan so he can add you to our group.
126.96.36.199.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
188.8.131.52.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.
184.108.40.206.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.
220.127.116.11.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.
git commit -m "<brief description of the changes>"
18.104.22.168.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.
22.214.171.124.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.
126.96.36.199.10. Using graphical programs to manage repositories¶
Several graphical programs are also available to manage Git repositories