on multiple machines (instead of one central repository), the risk of project loss due to server failure or some other catastrophe is much lower. HIGH AVAILABILITY High availability -- Server down? Network down? No problem. Work in your repo (commit, view history, branch, etc) to your heart's content. Try that with Subversion!
objects in the .git directory, saving you space. COLLABORATION FRIENDLY Git makes it easy to collaborate on projects with groups of contributors and with great services like Bitbucket, Gitlab and (of course) Github, git's collaboration friendliness is even further magniﬁed.
is usually a directory that is tracked by git. Git tracks the states of the ﬁles in the directory and with various commands, informs you of the status of you repository. To start tracking a directory (to initialize a git repo):
that we need to mention a bit is the way git thinks about data in comparison to how other VCS. Most other systems (CVS, Subversion, Perforce etc.) store information as a list of ﬁle-based changes ﬁg: ﬁle-based changes
of snapshots of a miniature ﬁlesystem. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your ﬁles look like at that moment and stores a reference to that snapshot. ﬁg: changes as snapshots
cli, it displays paths that have differences between the index ﬁle and the current HEAD commit, paths that have differences between the working tree and the index ﬁle, and paths in the working tree that are not (yet) tracked by Git (and are not ignored by ‘gitignore’) $ git status
you use the command git add. What this command does is to update the ‘index’ using the current content found in the working tree to prepare the content stages for the next commit. $ git add <file_name> Suppose you have a lot of changes in a ﬁle and you don’t want to commit all the changes at once: $ git add <file_name> -p The ‘-p’ ﬂag interactively chooses chunks in the ﬁle to add to the ‘index’ or staging area.
a new commit along with a log message from the user describing the changes. $ git commit If you have changes in the working directory and you really want to add all ﬁles with a simple commit message $ git commit —amend To change/update the last commit - in the event that you don’t like the commit message or to add another ﬁle to the same commit. $ git commit -am “my super awesome commit message” * Note that any ﬁle you have in the index gets added when you use this commit option and yeah, it rewrites history so use carefully.
It is exactly like any other branch. The only reason nearly every repository has one is that the git init command creates it by default and most people don’t bother to change it. Which when looked at from a birds eye view, looks ‘something’ like this:
to a commit object - identiﬁed by a ‘sha’, it’s fairly easy to select commits as bases for our new branches. $ git branch <branch_name> [<start-point>] (source: man git-branch) Creating a branch with a start point. $ git branch feature/authentication-patch 34ac55…
the working tree. Updates ﬁles in the working tree to match the version in the index or the speciﬁed tree. If no paths are given, git checkout will also update HEAD to set the speciﬁed branch as the current branch. It moves HEAD to a different branch (or commit) and updates the working directory to match it. $ git checkout <branch_name>
a valid commit that isn’t a branch. $ git checkout 34ac55… This can be used to quickly check inspect an old version of your project. * Being in the ‘detached head’ state can however be dangerous because if you checkout to a grandparent of HEAD for instance and then make commits, you loose being able to get back the commits even after switching to other branches.
of bytes that could be anything, like a text ﬁle, source code, or a picture, etc. • Trees A git tree is like a ﬁlesystem directory. A git tree can point to, or include Git “blob” objects or other git trees. • Commits A git commit object includes: Information about who committed the change/check-in/commit, a pointer to the git tree object that represents the git repository when the commit was done and the parent commit to this commit (so we can easily ﬁnd out the situation at the previous commit). • Tags A git tag object points to any git commit object. A git tag can be used to refer to a speciﬁc tree, rather than having to remember or use the hash of the tree.
objects refs [ a text ﬁle that is shown as project description in web frontend ] [ repository wide conﬁguration ] [ text ﬁle showing currently checked out branch ] [ where git hooks are stored ] * Git hooks are scripts that run automatically every time a particular event occurs in a Git repository [ use this ﬁle to ignore ﬁles (like .gitignore but isn’t versioned) ] exclude [ Git’s internal warehouse for blobs, indexed by SHAs - where the ’objects’ are stored ] [ Where refs (including) branches live ] heads remotes tags stash [ where your git branches are managed ] [ remote branches ] [ … here be the tags ] [ an ascii text ﬁle that has your stash SHAs ]
repository to a new directory. The “working copy” is a full-ﬂedged Git repository—it has its own history, manages its own ﬁles, and is a completely isolated environment from the original repository. $ git clone <repo_url> <repo_url> must be a valid ssh, git, ftp or http(s) url
named commits (since the time their histories diverged from the current branch) into the current branch Say we have a repository with 2 branches as shown below: * see the git documentation for more options ( http://git-scm.com/book)
just moving the branch pointer forward, Git creates a new snapshot that results from this merge and automatically creates a new commit that points to it. This type of commit referred to as a merge commit, and is special in that it has more than one parent. The above commands leave our repository in a new state. ﬁg: merge commit
go smoothly and you’ll have something called a merge conﬂict. $ git merge iss53 Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result. If your changes on the iss53 branch modiﬁed the same part of a ﬁle as a new change on the branch being merged unto, you’ll get a merge conﬂict.
(fix conflicts and run "git commit") Unmerged paths: (use "git add <file>..." to mark resolution) both modified: index.html no changes added to commit (use "git add" and/or "git commit -a”) Running ‘git status’ will give some insight into what is happening. Despite trying to merge branches, we still have ‘unmerged paths’. This is a merge conﬂict and git status shows the ﬁles that have conﬂicts under ‘Unmerged Paths’.
the ﬁles that have conﬂicts, so you can open them manually and resolve those conﬂicts. Resolving Conﬂicts Your ﬁle will contain sections that have markers and the conﬂicted ﬁle will look something like: <<<<<<< HEAD:index.html <div id="footer">contact : firstname.lastname@example.org</div> ======= <div id="footer"> please contact us at email@example.com </div> >>>>>>> iss53:index.html * you can then stage your updated ﬁles and commit to complete the merge.
object - commits, blobs, stashes, branches etc. $ git show [<branch_name>] | [<sha>] Git blame Show what revision and author last modiﬁed each line of a ﬁle. The blame command is a Git feature, designed to help you determine who made changes to a ﬁle. $ git blame <file_name> * see the git documentation for more options ( http://git-scm.com/book)
You’ll often ﬁnd, when using branches, how easy it is to commit to a different branch (say, testing branch) than the one intended (master). $ git cherry-pick testing [ apply to the current branch the change introduced at the tip of the testing branch ] $ git cherry-pick testing..hotfix [ apply to the current branch the changes introduced in ‘hotﬁx’ that are not in ‘testing’ ] * see the git documentation for more options ( http://git-scm.com/book)
of the branch to a different commit. This can be used to remove commits from the current branch. Recall: when you checkout a branch, it changes HEAD to point to the new branch ref, populates your Index with the snapshot of that commit, then copies the contents of the Index into your Working Directory. ﬁle.txt has been modiﬁed and the repo is in a clean state. For instance, if we had our repository as such,