Difference between revisions of "Guide to Using Git"

From GlueXWiki
Jump to: navigation, search
(Overview)
(Overview)
Line 1: Line 1:
 
= Overview =
 
= Overview =
This document is intended to contain information useful to GlueX users and code developers for using git in the GlueX software environment.  Many expert operations (e.g. making a tagged release) and shortcuts are excluded.  See the git web-book for full documentation:
+
This document is intended to contain the basic information needed for GlueX users and code developers to use git in the GlueX software environment.  Many expert operations (e.g. making a tagged release) are excluded.  Also, some shortcuts/features are skipped so as not to clutter this document. See the git web-book for full documentation:
 
=== References ===
 
=== References ===
 
* Guide: https://git-scm.com/book/en/v2
 
* Guide: https://git-scm.com/book/en/v2

Revision as of 23:04, 30 July 2015

Overview

This document is intended to contain the basic information needed for GlueX users and code developers to use git in the GlueX software environment. Many expert operations (e.g. making a tagged release) are excluded. Also, some shortcuts/features are skipped so as not to clutter this document. See the git web-book for full documentation:

References

First-time Setup

The first time you use git on your machine, setup the following information (optional):

git config --global user.name "John Doe"
git config --global user.email "username@jlab.org"
git config --global core.editor vim

Creating a local clone of the repository

The first thing you need to do is to create a clone of the master repository on your local machine. The "git clone" command pulls all of the code, branches, etc. for the entire history of the project into the current, local directory.

Setup Philosophy

  • In general, you probably want to have several separate copies of the repository built simultaneously on your machine. For example, you may want to have a program running off of a tagged release, and meanwhile develop code separately on a different branch.
  • The recommended way of doing this is to have a wholly separate clone of the repository for each tagged release, in addition to one (or multiple) clone(s) of the repository used for code development.

Examples

To create clones of the master repositories into the directories <mydir>:

# SIM-RECON
cd $GLUEX_TOP/sim-recon/
git clone https://github.com/jeffersonlab/sim-recon/ <mydir>

# HDDS
cd $GLUEX_TOP/hdds/
git clone https://github.com/jeffersonlab/hdds/ <mydir>

References

Creating & Switching Branches

  • In git, branches are simply pointers to different snapshots of the content of the git repository.
  • By default, the "master" branch is created on your local machine after performing "git clone," but it is not a special or unique branch. There is no inherent definition of a "trunk" in git like there is svn, just a series of branches.
  • However, for GlueX, we treat the remote, "origin," "master" branch of the sim-recon/hdds/etc. repositories (stored on Github) as the "trunk" from which we create tagged releases.

Examples

To create the branch <mybranch> (whose content will be identical to the current branch):

git branch <mybranch>

To show which branch you are currently using:

git branch

To switch to the branch <mybranch> (this replaces the local files/folders of your current branch with those of the new branch):

git checkout <mybranch>

References

Adding files and/or Committing changes

  • There are two cases where you might want to commit changes: New content and changes to existing content. In both cases, you must first "stage" the change with "git add," before committing it with "git commit."
    • Note that any changes made after "git add" but prior to "git commit" will NOT be committed; run "git add" again on the changed files in order to re-stage them for committing.
    • When you run "git commit" the text editor defined by the environment variable $EDITOR will be launched for you to add commit comments.
  • These operations add/commit the changes to your current, active branch.

Examples

To stage a file/folder for the next commit (and/or add a new file):

git add <myfile>

To commit all of the staged files/folders in the current folder to git:

git commit

To commit all changes to "tracked" files/folders in the directory to git (bypassing the "add" staging: similar to "svn commit"):

git commit -a

References

Terminology

  • Tracked/untracked files: Untracked files are files that have never been added to git (via git add). Tracked files are ones that have been previously added to git.

Removing Files from Git

  • Use "git rm <myfile>" followed by "git commit" to remove files from git, similar to how you would for svn.

Examples

To remove the file/directory <myfile> from git:

git rm <myfile>
git commit

References

Remote Repositories

  • The "origin" remote repository is the repository that you cloned when you initialized your setup with "git clone."

Examples

To list the remote repositories that your clone is connected to

git remote -v