Git: Difference between revisions

From HaFrWiki42
Jump to navigation Jump to search
mNo edit summary
Line 4: Line 4:
Initially designed and developed by Linus Torvalds for Linux kernel development, Git has since been adopted by many other projects.
Initially designed and developed by Linus Torvalds for Linux kernel development, Git has since been adopted by many other projects.
Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.
Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.
== Stages ==
This is the main thing to remember about Git if you want the rest of your learning process to go smoothly. Git has three main states that your files can reside in:
* Committed,<br>Committed means that the data is safely stored in your local database.
* Modified, <br>Modified means that you have changed the file but have not committed it to your database yet.
* Staged, <br> Staged means that you have marked a modified file in its current version to go into your next commit snapshot.
This leads us to the three main sections of a Git project: the Git directory, the working directory, and the staging area.
* Git directory<br>The Git directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone
a repository from another computer.
* Working directory<br>The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for
you to use or modify.
* Staging area<br>The staging area is a simple file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the index, but it’s becoming standard to refer to it as the staging area.
The basic Git workflow goes something like this:
# Modify files in your working directory.
# Stage the files, adding snapshots of them to your staging area.
# Commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.


== Setup ==
== Setup ==

Revision as of 14:45, 24 April 2013

Git [1], is a distributed revision control and source code management (SCM) system with an emphasis on speed. Initially designed and developed by Linus Torvalds for Linux kernel development, Git has since been adopted by many other projects. Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.

Stages

This is the main thing to remember about Git if you want the rest of your learning process to go smoothly. Git has three main states that your files can reside in:

  • Committed,
    Committed means that the data is safely stored in your local database.
  • Modified,
    Modified means that you have changed the file but have not committed it to your database yet.
  • Staged,
    Staged means that you have marked a modified file in its current version to go into your next commit snapshot.

This leads us to the three main sections of a Git project: the Git directory, the working directory, and the staging area.

  • Git directory
    The Git directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone

a repository from another computer.

  • Working directory
    The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for

you to use or modify.

  • Staging area
    The staging area is a simple file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the index, but it’s becoming standard to refer to it as the staging area.

The basic Git workflow goes something like this:

  1. Modify files in your working directory.
  2. Stage the files, adding snapshots of them to your staging area.
  3. Commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.

Setup

To setup git [2]

Username

First you need to tell git your name, so that it can properly label the commits you make.

 # Sets the default name for git to use when you commit.
 $ git config --global user.name "harm"

Email

Git saves your email address into the commits you make. We use the email address to associate your commits with your GitHub account.

 # Sets the default email account for git when you commit
 $ git config --global user.email "h.frielink@<you-server-name>"

Cheat Sheet

Always handy are Cheat Sheets [3].

Create & Clone Add & Remove
Create new repo git init Add changes to INDEX git add <filename>
Clone local repo git clone /path Add all changes to INDEX git add *
Clone remote repo git clone username@host:/path/to/repo Remove / Delete git rm <filename>


Commit & Synchronize Branches
Commit changes git commit -m "Message" Create new branch git checkout -b <branch>
i.e.: git checkout feature-x
Push changes to remote repo git push origin master Switch to master branch git checkout master
Connect local repo to remote repo git remote add origin <server> Delete branch git branch -d <branch>
Update local repo with remote changes git pull push branch to remote repo git push origin <branch>


Merge Tagging
Merge changes from another branch git merge <branch> Create tag git tag <tag> <commit-ID>
View changes between 2 branches git diff <src-branch> <trg-branch> Get commit IDs git log

See also

top

Reference

top

  1. Wikipedia Git-description, Git Software
  2. help-github, Setup.
  3. Roger Dudler, Sheet Cheat