Git QuickStart

Git QuickStart

Git (download from here) is a Distributed Version Control Systems (DVCSs).

Brief description

A Version Control System is a system that records changes to a file or set of files over time so that you can recall specific versions later.
Centralized Version Control Systems (CVCSs) - such as CVS, Subversion, and Perforce - have a single server that contains all the versioned files, and a number of clients that check out files from that central place. For many years, this has been the standard for version control.
In Distributed Version Control Systems (DVCSs) - such as Git, Mercurial, Bazaar or Darcs - clients don’t just check out the latest snapshot of the files: they fully mirror the repository. Thus if any server dies, and these systems were collaborating via it, any of the client repositories can be copied back up to the server to restore it.

Guides

To download a "Quick Start" pdf guide (edited by Stefano Mariani) click here. For a more in-depth guide refer to GitBook, from which most of the material in such pdf guide is taken.

Basic Command line list

As a quick-access reminder, here follows a list of Git most known and used command line "commands" (sorry for the awkward wordplay) along with a brief description (uppercase-initiated strings are variables with their intuitive meaning):

  • git init - to start tracking an existing local project (type in project dir);
  • git clone [Url] - to mirror locally an existing remote Git repository (type in your preferred target dir which will host your local copy of the project);
  • git add [Filepath] - to begin tracking a new file (works with dirs recursively);
  • git commit -a -m "[Message]" - to register the current state of your project into Git repository;
  • git rm --cached [Filepath] - to stop tracking a tracked file without removing it from your hard disk (works with dirs recursively);
  • git status - to know which files are in which state (committed, staged, untracked basically);
  • git log - to know the repository history (lists all of your previous commits);
  • git branch - to list existing branches;
  • git checkout -b [Branchname] - to create a new branch and suddenly switch to it (create a local copy of your working project and start working on it);
  • git merge [Branchfrom] -m "[Message]" - to merge an existing branch into your current working branch;
  • git tag -a [Tagname] -m "[Message]" - to create a named release of your current working project (a "tag", tipically a non-modifiable snapshot of your current branch);
  • git remote add [Alias] [Url] - to create a shortname to use in place of an existing remote repository complete url (it does not pull dow anything);
  • git pull [Remotealias] - to download all changes made in the target remote repository into your local copy of that repo;
  • git push [Remotealias] [Branchname] - to upload the specified branch to the target remote repository (succeed only if nobody has pushed since your last push)
  • git push [Remotealias] --tags - to upload all your local tags to the target remote repository;
  • git checkout -b [Branchname] [Remotealias]/[Remotebranch] - to start tracking an existing remote branch on the specified remote repository, naming it locally as you prefer (needs git fetch origin first);
  • git clone -b [Branchname] [Remotealias] - to clone only a single branch other than the whole remote Git repository.

Advanced Command line list

Some more involved commands, useful in a plethora of situations:

  • git ls-tree -r [Branch] --name-only - to show tracked files
  • git diff --name-status [Branchfrom]..[Branchto] - to have a quick look at the main differences between two live branches of the project;
  • git diff [Branchfrom]:[Filepath] [Branchto]:[Filepath] - to have a complete description of the differences that two branches have w.r.t. the given file;
  • git checkout [Branchfrom] [Filepath] - to "merge" a single file from the given branch into the working one (notice actually it is more likely an overwrite other than a merge, so be careful);
  • git commit --amend -m "[Msg]" - to replace the last commit message with Msg;
  • git checkout -- . - to discard all the staged changes at once;
  • git checkout -b [Branchto] [Tagfrom] - to create a branch out of a tag and suddenly switch to it;
  • git reset --hard [CommitHash] - to revert the file system status to the given commit;
  • git push [RemoteAlias] :[BranchToDelete] - to delete a remote branch.
  • git log [TagFrom]..[TagTo] > changelog.txt - to print out to a text file the commit log between two tags

    Environment

Logo

Riferimenti

Giovanni Ciatto email  |  Andrea Omicini email  |  Stefano Mariani email

Link

Official  |  APICe  |  Google Code  |  SourceForge  |  FaceBook

2P  |  A&A  |  MoK  |  ReSpecT  |  T4J  |  T4Jn