Skip to content

Introduction to Git

Alexander Nitsch edited this page May 15, 2014 · 2 revisions

Git Version Control

General

  • Git is a distributed version control and file management system
  • everyone gets his/her own copy of the project on his own computer, that means:
  • work offline = very fast
  • tracking all changes of multiple developers (modifications, adding, movings, deletions,...) and merging them

Git Basics

Git Data Flow

  • working directory
  • local directory of your git-project --> location of your source code / files
  • here you make your changes
  • index (cache) - Staging Area
  • you can not commit your changed files until you have "staged" them (add)
  • after staging your files (taking a kind of a snapshot), you can commit
  • purpose: the staging area allows you to control what you want to commit
  • not completed modification can left out of the commit
  • after committing, the staging area will be wiped
  • local repository
  • is a git-project on your local computer
  • by using a remote repository (e.g. GitHub), the local repository shall be an exact copy (clone) of the remote-git project (in most cases of the openETCS-project)
  • changes to your local files will be saved in your local repository by committing
  • remote repository
  • is a centralized git server that hosts git-projects (GitHub)
  • is not needed for using Git, but it is an easy way to share Git-projects to different users/developers

Installation

  • on windows, there are different ways to use git:
  • via command line (bash) (which is the recommended method to learn Git): http://git-scm.com/
  • or you can use graphical interfaces (GUI Clients): http://git-scm.com/download/gui/win
  • download and install your prefered method
  • while installing the program, on "Select Components" select "Simple context menu (Registry based)" --> "Git bash Here" and "Git GUI Here", that eases the handling with Git (later using the default settings is fine)
  • on Linux (e.g. Ubuntu):
  • run in command line: sudo apt-get install git

Setting Up a Git Repository

  • git init
  • the git init command initializes a new Git repository, this places a project under revision control
  • a (hidden) .git folder will be added, the revisions will be recorded here (contains the necessary metadata)
  • git init the current directory will be transformed into a Git repository
  • git init <directory> an empty Git Repo will be created in the specified directory
  • git clone
  • the git clone command creates a copy of an existing Git repository
  • git clone <repo> clone a given (also local or remote) repository onto your local machine
  • git clone <repo> <directory> cloning the Repo in the specified directory locally
  • there is no distinction between working copy and the central repository (unlike SVN) - they are all full-fledged git repositories
  • git config *git wants to know who you are, therefore run git bash, type the following lines and confirm each line by hitting enter:
  • git config --global user.name "Name"
  • git config --global user.email "email@example.com"
  • these information will be recorded with your commit/snapshot

Recording Snapshots

  • git add
  • the git add command moves changes from the working directory to the staging area
  • this allows you to prepare a snapshot before committing your work
  • git add <file> [stages all changes in the for your next commit]
  • git add <directory> [stages in the specified ]
  • git commit
  • commits the staged snapshot, this command launches an editor (vim by default) for adding a commit message, after saving and closing the editor your commit will be be created
  • instead of starting an editor you can type git commit -m ""
  • the git commit -a command commits a snapshot of all changes in the working directory, but only those files that are added at some point in their history (git add)

to be continued

Sources:

Clone this wiki locally