- Install Git
- Create a GitHub account
- Open Terminal
/Applications/Utilities/Terminal.app
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global color.ui true
git config --list
Create the remote repository at GitHub as My Project
.
Create the local repository.
mkdir -p ~/Code/myproject/ && cd ~/Code/myproject/
git init
echo "# My Project" > README.md
git add README.md # Or `git add .` for adding all
git commit -m "First commit"
git remote add origin [email protected]:myusername/My-Project.git
git push -u origin master # subsequently `git push`
Go to https://github.com/myusername/My-Project (or refresh page).
echo "*.DS_Store" > .gitignore
git add .gitignore
git commit -m "Added ignore file"
git clone [email protected]:theirusername/Their-Project.git`
git pull origin master
Add new feature branch:
git checkout -b my-new-feature-branch # `-b` is shortcut for creating and switching to new branch
# work on new feature
git status
git add new-file.html
git rm worthless-file.html
git commit -m "First edit for the feature"
# work some more
git add more.min.js
git diff --staged
git commit -m "Second edit for the feature"
# You could push my-new-feature-branch out to remote if collaborating with others
# git push origin my-new-feature-branch
Update with new feature branch:
git checkout master
git pull origin master
git merge someone-elses-new-feature-branch
git push origin master
If master is ahead of you:
# You could `git pull && git push`...but "merge commits" are ugly
git fetch # you should be on master
git checkout my-new-feature-branch
git rebase master
git checkout master
git merge my-new-feature-branch
If you have conflicts:
git fetch # you should be on master
git rebase
# fix conflicts
git add broken_file.html
git rebase --continue
Delete new feature branch:
git checkout master
git branch -d my-new-feature-branch
git push origin --delete my-new-feature-branch # deletes remote branch
git remote prune origin # deletes remote branch more
git tag # list tags
git tag -a v0.0.2 -m "Version 0.0.2" # add new tag
git push --tags # push new tags
git checkout v0.0.1 # checkout tag
git reset --soft HEAD^ # Undoes last commit, files are back to staged
git reset --hard HEAD^ # Undoes last commit, and undoes the edits of those files! Nuclear option!
git status # Show (un)tracked/(un)staged files
git branch # Show branches and which one you're on
git branch -r # List all remote branches
git remote show origin # Show all remote branches
git log # Show the commits, or `git log --graph` for pretty
git show thelonggitlognumber1234567890 # Show old versions of files
git diff # Show diff between tracked and last commit
git diff thelonggitlognumber1234567890 # Show diffs between file versions
git blame file.html # Show author of change
# Go to GitHub project, click Fork
git clone https://github.com/yourusername/cool-forked-project.git
cd cool-forked-project
git remote add upstream https://github.com/theotherguy/cool-forked-project.git
git fetch upstream
git merge upstream/master
# Visit your repo webpage to send pull request
- You have a local copy of the repository, which complements local development with
rails s
/python manage.py runserver
- Branching for new features is easier than SVN
- Faster/smaller in size than SVN
- Just remember to visualize the local/remote + branch/master way of thinking
Double plus good.