How will we work together this semester? A big part of it will be using Git and GitHub. As you can see, our course website is built from source files (.Rmd, .css, and .html) in our Organization Repository where you will be contributing to its content once you have created a GitHub account and have joined our development team.
The real power of Git is in its version control, so be sure to read about it. We will practice getting everything up and running so you can take the first Sandbox Challenge—Sandbox Challenges are ungraded challenges I pose to you throughout the semester that emphasize learning a new skill that will be useful as you work through the assignments and project in this class. You will find the Sandbox Challenges in the current Semester Repository.
The following steps only need to be performed once, which will get you a working copy of a repository and configured for editing and pushing to the remote (shared) repository.
Create a local copy of our semester repository.
Create a folder on your computer for your repository (e.g., C:\Users\user\Repositories\sdd
).
Troubleshooting: please do not put your repository folders in Dropbox or One Drive or other cloud-based synchronization and backup folders. This is not how you share repositories across computers! Dropbox, OneDrive and other synchronization software will embed hidden files and folders, which can copy over to the repository and cause everyone problems. If you want your repository on another computer, clone it again on your second computer!
Open your command prompt or terminal (see Additional Resources above for links on how to access these)
Navigate to your repository directory
Clone your repository; once your done, you should now have a repository folder (e.g., sdd-2021) in your Repositories directory (see commands below)
cd path/to/Repositories # replace "path/to/Repositories" with the directory path
git clone https://github.com/spatial-data-discovery/sdd-2021.git
The URL for repositories can be copied to your clipboard from the GitHub website by clicking on the green Code button.
Configure your git.
cd sdd-2021 # change directory to semester repo
git config user.name dt-woods # replace "dt-woods" with your GitHub username
git config user.email dtwoods@email.edu # replace with the email address associated with your GitHub account
git config push.default simple # optional configuration
These steps outline the basic workflow for editing existing and creating new files in a repository, recording the changes (i.e., staging and committing), and sending the changes to the shared repository (i.e., pushing).
Edit an existing file on the repository (reference: Recording Changes to the Repository)
git pull
); if no changes, you will receive a message “Already up to date” otherwise, changes will be downloadedgit status
)
git diff
(if you forget what you did)git add -u
); alternatively, you can add individual files by name (git add edited-file.txt
)
git status
)
git commit -m "Add new author to contributors list"
)
-m
flag)git push
)
Add a new file to the repository
Save a new file in the repository (e.g., sandbox/newfile.py
)
From the command prompt or terminal, navigate to the cloned repository (use the cd
command)
Check for changes; any new files or new edits will be downloaded to your computer.
> git pull
Already up to date
Check the status of git (git status
)
> git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
newfile.py
nothing to commit but untracked files present (use "git add" to track)
Git should indicate the presence of an untracked file. This is different from a modified file because git has no history of this file (yet).
Add your new file (git add newfile.py
); this is called staging
> git add newfile.py
> git status
Git should indicate that you have changes to be committed.
Commit your changes; keep your commit messages brief and to the point. If you forget to add a message, you will be prompted to add a message.
> git commit -m "Create sandbox python script; Addresses #1"
Push your changes to the shared repository
> git push # or 'git push origin master' if it's the first push
You may be prompted for your Git username and password