every commit (full file, no diffs). Only new and modified files are hashed and stored. • Blobs are stored as compressed files in: • .git/objects/*/* • (sharded using first two SHA-1 characters into subdirectories) • Unreferenced (unreachable) blobs are garbage-collected every so often
can be used to annotate history (qa-tested, deployed, etc.) • can be shared across repositories, not pushed by default • heavyweight tags • immutable entities, have full commit info and are persisted and pushed across repositories • contain cryptographic signing mechanisms
aliases) stored in the local repository. • branches fetched from remotes are read-only and are labeled as [remote-name]/[branch-name] • branches can be set up to map to remote branches using .git/config directives • you can still push changes to remotes without setting up tracking by using explicit URIs
that can be merged as any other, but not modified locally. To merge changes from a remote: • git fetch remote-name • git merge remote-name/branch-name If you are tracking the current branch: • git pull [remote-name]
a remote repository if the push results in appending history to the branch without a merge: • git push remote-name branch-name If you‘re pushing a new branch to the remote, you can set up tracking for the branch: • git push –u remote-name branch-name
current = yellow reverse local = yellow remote = green [color "diff"] meta = yellow bold frag = magenta bold old = red bold new = green bold [color "status"] added = yellow changed = green untracked = cyan
greeting" [master ca59d46] Added greeting 1 file changed, 1 insertion(+) $ git status # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # nothing to commit (working directory clean)
by git (but are reported by git status as untracked). • Modifications to tracked files are displayed, but not commited automatically. • Staging allows choosing which changes to put into a commit. • A commit command takes every staged change and creates a new commit.
working copy checkout): • git init my-repo --bare To push changes to the repository, you need a clone to push changes from there: • git clone my-repo my-checkout • (...work...) • git push -u origin master
be created at any time by using the branch command: • git branch new-branch-name This creates a new branch at the revision currently checked out (but does not switch!): 00 01 03 04 master (checked out) new-branch-name
checkout command: • git checkout new-branch-name Or do it in one step: • git checkout new-branch-name -b 00 01 03 04 master new-branch-name (checked out)
want to merge: • git checkout main-dev-branch Merge changes into the working copy: • git merge feature-branch Resolve any merge conflicts and mark files as resolved, then commit: • git add <conflicted file>
main-dev-branch • git fetch remote-name • git merge \ remote-name/feature-branch Always fetch before merging remote branches! Local history for remote branches may not be up-to-date!
branches might become obsolete and deleted. To clean up remotely deleted branches: • git remote prune remote-name Git runs garbage collection periodically, but you can manually run it if desired: • git gc
don‘t want to commit just yet. Enter the stash stack: • git stash [save [--keep-index] [message]] This saves the complete changeset to the working copy. If using --keep-index (or -k), changes already staged will not be saved with the stash, but left in the working copy.
git stash list To view a specific stash content as a diff: • git stash show stash@{0} Substitute 0 with any of the numbers listed in the stash list to view that stash.
stash apply stash@{0} [--index] To throw away a stash (or all of them): • git stash drop stash@{0} • git stash clear To apply and drop in a single command: • git stash pop stash@{0} [--index]
out you should be doing something in a separate branch and have a stash you want moved: • git stash branch my-branch stash@{0} This will branch at the commit the stash was created and pop the stash into the working copy without commiting.