Git is a system for keeping track of changes in code. It’s particularly useful for collaboration (“Hello, world of fellow programmers!”) and reversion when a project’s source code has inadvertently ventured treacherously and irrevocably astray (fervently spamming CMD+Z is not always enough to re-establish baseline).
I obdurately refused to learn git for many years, because I am a doofus, and worked mostly solo on projects (verily to detriment). I recommend learning git, sharing code, and collaborating with others. Feedback is invaluable; you’ll get way better way faster than I did working this way.
Because I didn’t exactly hit the ground running, in terms of adapting git, I’ve typed out loose directions for personal reference—and for others whose interest is piqued and could use a guiding hand.
First: Initialize Git
- Install Xcode command line tools:
open new Terminal tab/window
xcode-select --install
(orxcode-select --reset
) (see: link) - Go through seemingly pertinent GitHub setup guides: link
- Generate SSH key (and add passphrase to keychain): link
- Add SSH key to GitHub account: link
Second: Create Origin Repository
- Visit: link
- Choose repository name and public/private (skip other options)
- Create repository
- Leave succeeding page open (it lists helpful commands and SSH URL needed below)
Third: Initialize & Commit Remote Repository to Origin
- Navigate to local, top-level project directory (e.g., WordPress theme or root):
open new Terminal window/tab
cd [Local Path]
(drag folder from Finder to Terminal to get path) - Add remote repository:
git init
git remote add origin git@github.com:[GitHub Username]/[Repository Name].git
- (Pull remote repository:)
git pull origin master
(see: link) - Create
.gitignore
file to ignore files in repository:
touch .gitignore
edit w/ text editor (see: link for guidance w/ file contents) - Add files and commit changes:
git add -A
git commit -am "[Message]"
(e.g.,git commit -am "first commit"
) - Push to remote repository:
git push -u origin master
Misc. Maintenance
- View status:
git status
- Remove .DS_Store:
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
(see: link)
git add -A
git commit -am "delete .DS_Store"
- Remove remote repository:
rm -rf .git
rm .gitignore