How To Use Git

From Genome Analysis Wiki
Revision as of 14:50, 9 September 2011 by Mktrost (talk | contribs) (→‎How Do I...)
Jump to navigationJump to search

Some useful suggestions/links/information on how to use git.

Learning Git

Presentations

If you want to use a GUI, one option is: SmartGit GUI

Practical

Using Git Example

Cheat Sheet

GitHub

We use GitHub to host our software repositories - take a look at a brief overview


Git Terms

  • Repository - holds files and their history
    • Bare repository - no visible files, just the database that holds the stored information
  • Clone - copy a repository
  • Local/working - the directory/repository where you make your changes/work in
  • Remote/source - the repository that your local/working repository was cloned from/where you send your completed changes.
  • Commit - a version/revision of your repository or the act of creating a version/revision
    • on a commit, changes are only stored in the local/working repository
  • Pull - update your local/working repository with any changes that have been made to the remote/source (you do not automatically see the changes)
  • Push - update the remote/source with changes that you have made in your local/working repository
  • Branch - alternate paths of work that allows you to commit/push/pull without affecting the other paths
  • Master - the main/default branch
  • Merge - bring in changes from another branch


Git FAQs

How Do I...

Learn how a specific command works

Command Example
git help <command> git help clone
man git-<command> man git-clone
git-<command> -h git-clone -h

Turn an already existing directory into a Git Repository

Create a remote bare Git repository for a repository to push to/pull from

Use a Previously Setup Repository

Clone it:

 git clone <repository to be cloned> [optional new directory name]

Update files

  • Edit a file.
  • When done editing, commit them, entering a description when prompted (2 ways):
    • git commit -a
    • git add (adds to the index/stage); git commit

Identify non-committed changes

  • Using Command-Line (2 ways)
    • git status
    • git diff
  • Using git-gui
    • They are listed under Unstaged Changes

Stage files/changes prior to committing them

  • Using Command-Line (multiple ways)
    • git add <file1> <file2> (adds specified files)
    • git add . (adds all files)
  • Using git-gui (multiple ways): Should see files move from Unstaged to Staged
    • Click on the file icons in the Unstaged Changes window
    • 2 Step process
      1. Select the files to be staged in the Unstaged Changes Window;
      2. Commit->Stage To Commit

Commit Changes

  • To see staged files use:
    • git diff --cached
  • Using Command-Line
    • git commit

Note: you need to use "git add" to incrementally "add" changes to the index before using the commit command

  • Using git-gui
    • Press the "Commit" button

Merging Changes

  • Command-Line
    • Merge <branchname> to the current branch:
      • git merge <branchname>
    • If independent enough, nothing more to do than commit.
    • If conflicts, use git status to get list of files that need to be resolved
      • Update the conflict files either by hand or using a merge tool:
        • git mergetool -t <tool>
    • Add & Commit the changes
  • To Undo a merge before committing:
    • git reset --hard HEAD

Pulling in Changes from source repository (the one you cloned from)

  • In master:
    • git pull
    • Then resolve any unresolved merges & commit.

Ignoring files

You can setup git to ignore files with certain names, extensions, etc.

  • git config core.excludesfile ~/git/config/ignoreFiles
  • Update ignoreFiles:
# Ignore editor created temp files
*~


More - COMING SOON!