Git Client Installation for Mac
Overview
These installation instructions are Mac-specific!
A Git installation script for Windows is located here.
The commands below must be done one at a time. Make sure each one is successful before continuing to the next step. Please do not get hung up on version numbers. Use the latest version for any package you install!
Git Client Installation (Mac)
Git is a software version control system. It allows us to maintain multiple (historical) versions of our files, so that we can track changes and roll back to a previous version if needed. We will use the GitHub website (www.github.com) to backup our files, as well as for deploying our web applications to the public World-Wide Web.
Git uses the concept of source code repositories, or repos. A repository is a named collection of files. We will create a local (on our of computer) git repository called main. We will create a remote branch on the GitHub website called origin, to which we will push (upload) our files as a backup. When it’s time to submit your files to Gradescope, you will “pull” them from GitHub into Gradescope.
Note
“Note: if you are using VS Code on Mac, you will need to do the following quick configuration step first!”
* Open the Settings (menu item Code, Preferences, Settings), and search for `git.TerminalAuthentication`. * Uncheck the box for Git Terminal Authentication. This must be unchecked, so that git will prompt you for a password. Failing to uncheck this box will result in an error "Missing or invalid credentials" later on. * Close any open terminal windows.
Installing Git command-line tools
Open a Terminal window (menu item Terminal, New Terminal).
Change into your django directory. Use brew to install git.
You will only need to do this once.
# change into django directory cd ~/Desktop/django # install the git toolkit using brew brew install git
GitHub set up
If you do not already have an account on GitHub, go create one now.
On the www.github.com website,
create a respository (repo) called cs412
.
Local set up
Create a New (local) Git Repository*
These steps will intialize your local git repository and set some configuration parameters.
You will only need to do these steps once.
# change into Django directory cd ~/Desktop/django # create git repository, check in files git init git add . git commit -m "initialize repository" git branch -M main # set git congifguration parameters git config --global user.name "Your Name" git config --global user.email "username@bu.edu"
Connect the remote branch (from GitHub) to your local file system
Use this command to connect the remote branch to your local git branch.
When you attempt to do this, you should be prompted for a username and password.
The username is your github.com
username (mine is azs-bu
). Check yours.
In the password field, you must use a Personal Access Token. This is a special password
that you will generate from the github website. Follow the instructions here:
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token.
Set the expiration to be at least 90 days so you do not need to change it for the
rest of the semester.
Your should only need to do this once!
# add the remote branch (from github) to the local repository # your remote hook will be different -- get it from your github account!! git remote add origin https://github.com/azs-bu/cs412-examples.git
The first time you run this command, git will prompt for your username and password. Use your github username. When it asks for a password, you will now have to supply what’s called a personal access token (PAT) instead of a password. To generate this PAT follow the directions on the github website (they have screenshots you can follow).
.gitignore
There are several files that we do not want to push to the git repository, including
python compiled/bytecode files (*.pyc
), virtual environment files, cache files,
log files, as well as some static resources.
To prevent adding these to the git repository, create a plain text file in your django
directory called .gitignore
. Here is the content to put into the .gitignore
file:
# Python bytecode files *.pyc *.pyo __pycache__/ # Virtual environment (TODO: add other virtual environment names as needed -> not necessary if using `pipenv`) venv/ env/ .venv/ .env/ # Django environment variables .env .env.* # Django migrations (temporary or backup files) */migrations/__pycache__/ */migrations/*.pyc # Database db.sqlite3-journal # Static and media files # static/admin is created on the Apache-server when we create the sybmolic link # (but is not necessary locally or on GitHub) /static/admin/ # Django cache files *.log *.pot *.mo *.pid *.cache *.coverage *.coverage.* # Editor and IDE settings .vscode/ .idea/ .spyderproject .spyproject *.sublime-project *.sublime-workspace # Operating system files .DS_Store Thumbs.db desktop.ini # Pipenv and Poetry .python-version # Coverage reports htmlcov/ .coverage .coverage.*
Using git command-line tools
Checking status, adding files, and committing changes
Use these commands to check the status of your repository, add files, and commit changes.
Always write a good comment when you commit changes, these will be important if (when) you need to roll back to a previous version.
# check status of repository git status # add all local changes to repository git add -A # commit changes git commit -m 'input some useful comment here'
Push local changes to the remote branch
Use this command to push your local changes up to GitHub.
# push local changes to remote branch git push origin main
Your will need to do this every time your commit changes!
Do you have suggestions for improving these instructions?
Please share them with Aaron.
[cs_people]: http://cs-people.bu.edu [putty]: https://www.putty.org/ [django_running]: ../resources/django_running.png [installation_mac]: