Managing Projects with Git (and other command-line skills) Dr. Chris Mayfield Department of Computer Science James Madison University Feb 18, 2020
Part 1: Group Repository
What is Git/GitHub? Git is a version control system GitHub is a social network Tutorials: ◮ https://guides.github.com/activities/hello-world/ ◮ https://kbroman.org/github tutorial/ Cheat Sheet: ◮ https://education.github.com/git-cheat-sheet-education.pdf Feb 18, 2020 Managing Projects with Git 3 of 14
Setup (IMPORTANT) git config --global user.name "firstname lastname" ◮ select a name that is identifiable for credit when reviewing version history git config --global user.email "email address" ◮ select an email address that will be associated with each history marker git config --global color.ui auto ◮ automatic command line coloring for Git for easy reviewing Feb 18, 2020 Managing Projects with Git 4 of 14
GitHub simplified 1. Clone your repository (one-time setup) ◮ git clone https://github.com/cs374/ teamname .git 2. Make changes to the files ◮ Using your favorite editors, dev tools, etc. 3. Add new files, commit changes ◮ git add newfile.txt ◮ git commit -m ”this is what I changed” 4. Pull changes from team members ◮ git pull 5. Push your changes to the repository ◮ git push Feb 18, 2020 Managing Projects with Git 5 of 14
Git quick reference Typical workflow merge in the latest commits git pull . . . make changes to your files what files have I changed? git status git diff show changes I have made save changes to repository git commit -m "message" git push upload my latest commits Other commands add new FILE to repository git add FILE remove FILE from repository git rm FILE git mv SRC DST move/rename in repository undo local changes to FILE git checkout FILE git help show a list of git commands Feb 18, 2020 Managing Projects with Git 6 of 14
Using meld with git In the Linux lab, use meld . instead of git diff Feb 18, 2020 Managing Projects with Git 7 of 14
Part 2: Group Database
Your group database (My example group name is absent ) To connect using psql ◮ psql -h data.cs.jmu.edu absent Remember to change the owner ◮ CREATE TABLE person (pid integer, name text); ◮ person is owned by current user by default ◮ ALTER TABLE person OWNER TO absent; ◮ person is now owned by the entire group GP2 will use psql to import data psql -c "\copy person FROM person.csv WITH CSV HEADER" absent Feb 18, 2020 Managing Projects with Git 9 of 14
Input and output Pipelining: program1 | program2 ◮ make the output of p 1 the input of p 2 ◮ can be used to chain multiple processes ◮ grep 2012 movies.csv | sort | head -n 20 Redirection: program < input file > output file ◮ read a file instead of the keyboard ◮ write a file instead of the terminal ◮ psql absent < create.sql > results.txt These operators work on Linux, Mac, and Windows! Feb 18, 2020 Managing Projects with Git 10 of 14
Environment variables Instead of typing: ◮ psql -h data.cs.jmu.edu -U mayfiecs absent Define variables: ◮ export PGHOST=data.cs.jmu.edu ◮ export PGUSER=mayfiecs ◮ export PGDATABASE=absent ◮ psql (with no arguments) (add to ∼ /.profile to make them permanent) https://www.postgresql.org/docs/11/libpq-envars.html Feb 18, 2020 Managing Projects with Git 11 of 14
Password file (optional) Are you tired of typing your student number? ◮ Create a .pgpass file (and chmod 600 ) data.cs.jmu.edu:5432:*:username:password https://www.postgresql.org/docs/11/libpq-pgpass.html Feb 18, 2020 Managing Projects with Git 12 of 14
SSH keys (optional) Are you tired of typing your stu password? ◮ Run ssh-keygen on your machine (one-time setup) ◮ Run ssh-copy-id username@student.cs.jmu.edu ◮ Adds your public key to ∼ /.ssh/authorized keys Pick a good passphrase to protect your key (and identity) ◮ In case someone steals your laptop / private key file Tip: Add your public key to GitHub and clone over ssh ◮ Then you’ll never need to type your GitHub password Feb 18, 2020 Managing Projects with Git 13 of 14
SSH config (optional) Are you tired of typing long ssh commands? For example: ssh -L 5432:data.cs.jmu.edu:5432 username@student.cs.jmu.edu ◮ Create a ∼ /.ssh/config file with the following: Host stu Hostname student.cs.jmu.edu User username LocalForward 5432 data.cs.jmu.edu:5432 ◮ Now you can just type ssh stu (ideally with no password) Feb 18, 2020 Managing Projects with Git 14 of 14
Recommend
More recommend