I’m going to ignore most distributed aspects of git in this posting. This content addresses solo developer projects. Note that CWD is an abbreviation for your current working directory.
I use git on my laptop for most work, and when I have a 'milestone product,' I push that to my server.
To Do This | Type This |
Create a repo in CWD | git init |
Add content of CWD to git's tracking (if CWD is repo root or descendant) | git add . |
Put all tracked content of CWD and below into repo | git commit |
Put and track content of updated/new files in CWD and below into repo (combines add and commit) | git commit -a |
Status | git status |
Copy a project from a master repo | git clone url_goes_here |
Put your changes back in the master | git push |
Discover what you SHOULD have added | git diff |
Show what will get committed | git diff --cached |
Show what will get commited (alt.) | git status |
Abandon (completely destroy) a branch | git branch -D branch_name |
Show commit history [with metrics] | git log [--stat] |
Compare two branches | git diff master..my_branch |
Compare CWD with a version | git diff some_branch |
Show what changed in this_dir since last commit | git diff HEAD -- ./this_dir |
Do a file system based clone | git clone /path/to/master/for/project myrepo_dir |
Push a local repo to a NEW remote 'master' repo | git clone --bare repo_original repo_bare |
- In your commit message, the first line MUST be a summary line.
- One-time tasks, after you install git, before you use it for the first time
- git config --global user.name "Your Name"
- git config --global user.email "your_mailbox@example.com" </ul>
- Note that adding a file is not permanent. If you add+edit+commit+edit2+commit2, your file won't be included in commit2 (unless you do a "commit -a" to add+commit).
</ul>
Basic workflow. Suppose you're about to implement a feature you'll call Feature-X:
- cd somewhere_in_your_git-enabled_project
- git branch Feature-X
- This creates the branch, but does not make it your active branch. </ul>
- git checkout Feature-X
- This makes Feature-X your active branch. </ul>
- Lotsa editing
- git commit -a
- test and edit some more
- git commit-a
- git checkout master
- Makes 'master' your active branch. </ul>
- git merge Feature-X
- If the merge doensn't go smoothly:
- git diff
- More editing
- git commit -a </ul>
- Regression testing, and maybe more commits.
- git branch -d Feature-X </ul>