Note: configuration settings are not propagated from one repository to another during a clone.
Configuration file hierarchy:
core.filemode - false to ignore permission changes.
core.bare - boolean indicating if the repository has a working directory.
core.autocrlf - converts CRLF into LF when a file is added to the index, and vice versa when code is checked out onto the file system. core.editor - default editor, if not set git tries to use
user.name - name to be used in new commits. user.email - email to be used in new commits.
To check current settings
$ git config --list
Because git reads the same key from different files, some keys may be repeated. The configuration files are parsed in the order reported above. And the last value will be used.
Every git command has it's help page. There are three ways to get the manual page
$ git help <verb> $ git <verb> --help $ man git-verb
To each object is given an SHA1 identifier computed on it's content.
Low level commands that are not usually invoked directly.
write-tree- create a tree object using the current index.
commit-tree- create a new commit object using a tree object.
commit command is the concatenation of
init- create an empty repository or initialize an existing one.
init --bare- create a bare repository. No working directory.
clone- clone a repository into a new directory.
add- add file contents to the index.
rm- remove files from the working tree and from the index (
mv- move or rename a file, a directory, or a symlink.
status- shot the working tree status.
commit- capture an instantaneous of the current index and creates a commit object along with all the required tree objects.
tag- create, list, delete or verify a tag object.
diff- show changes between commits, commit and working tree, etc.
status- show the working tree status. Displays modified tracked files and untracked files.
ls-files- show information about files in the index and the working tree.
cat-file- provide content or type and size information for repository objects.
rev-parse- pick out and massage parameters. Print complete SHA1 hash for a tag or a partial hash.
hash-object- compute object-id and optionally creates a blob from a file.
commit --all- stages and commits all known, modified files.
add .- add, recusively, all the files from the current location to the index.
rm --cached- remove only from the index.
checkout HEAD -- <file>- restore the last committed version of
log --follow <file>- view log of file content (also works after file rename).
Create an empty repository or reinitialize an existing one
git init [directory]
--bare - Create a bare repository
Clone a repository into a new directory
git clone <repo> [<dir>]
Creates remote-tracking branches for each branch in the cloned repository, and creates and checks out an initial branch that is forked from the cloned repository's current active branch.
If specified, the repository is cloned into dir.
-b, --branch <branch> - Checkout
<branch> instead of the remote's HEAD
Show the working tree status
git status [<options>]
Displays paths that have differences between the index file and the current HEAD commit, paths that have differences between the working tree and the index file, and paths in the working tree that are not tracked (and are not ignored by gitignore).
-b, --branch- Show status of the branch
Add file contents to the index
git add [<pathspec>]
Updates the index using the current content found in the working tree, to prepare the content staged fo the next commit.
The "index" holds a snapshot of the content of the working tree, and it is this snapshot that is taken as the contents of the next commit. Thus after making any changes to the working tree, and before running the commit command, you must use the add command to add any new or modified files to the index.
This command can be performed multiple times before a commit. It only adds the content of the specified file(s) at the time the add command is run; if you want subsequent changes included in the next commit, then you must run git add again to add the new content to the index.
<pathspec>- Files or directories to add content from.
-u, --update- Update the index just where it already has an entry matching
<pathspec>. This removes as well as modifies index entries to match the working tree, but adds no new files.
Manage a set of tracked repositories
Without options it shows the list of existing remotes (defaults to
--verbose- Be a bit more verbose and show remote url after name.
add <name> <url>- Adds a remote named
<name>for the repository at
rm <name>- Removes the remote named
rename <old> <new>- Rename the remote named
show <name>- gives some information about the remote
prune- deletes all stale remote-tracking branches under
Download objects and refs from another repository
Once the remote is fetched it can be inspected and eventually merged to the current project. The fetch command only new work that has been pushed to that server since the repository has been cloned (or last fetched).
Remote tracking branches are updated.
<name>- Remote repository name. Defaults to origin.
--all- fetch all remotes.
--dry-run- show what would be done, without making any changes.
--prune- After fetching, remove any remote-tracking references that no longer exist on the remote.
Join two or more development histories together.
Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch.
--no-ff- No fast forward merge. Maintains track of the merged branch.
--no-commit- Do not automatically commit after a merge. Allows further modifications before commit.
Fetch from and integrate with another repository or a local branch
In it's default mode, the
pull command is a shorthand for a
fetch followed by a
<name>- Remote repository name. Defaults to origin.
Update remote refs along with associated objects
The command works only if you are pushing to a repository where we have write access and if nobody has pushed in the meantime, that is there are remote modifications that we do not have yet. It is also used to push a new branch to the remote repository.
<name> <branch>- Remote repository name and branch. Defaults to origin master.
Create, list, delete or verify a tag object signed with GPG.
Tipically a tag is used to mark a release point. Without options the command lists all the available tags in alphabetical order.
There are two main types of tags:
-l <pattern>- list tags with names that match the given pattern (shell wildcard).
-a <name>- creates an annotated tag with the given name.
-d <names-list>- delete existing tags with the given names.
Revert some existing commits
git revert <commit>
Undoes a committed snapshot. Instead of removing the commit from the project history, it appends a new commit with the resulting content. This prevents git from loosing history.
Proudly self-hosted on a cheap Raspberry Pi