Difference between revisions of "Guide to Using Git"

From GlueXWiki
Jump to: navigation, search
(Creating a local clone of the repository)
(Add new files to git)
Line 16: Line 16:
 
* Manual: http://git-scm.com/docs/git-clone
 
* Manual: http://git-scm.com/docs/git-clone
  
== Add new files to git ==
+
== Adding files and/or Committing changes to git ==
If you create new files or directories, they are initially "untracked;" you need to add them to git to track them. Note that the below example code does not commit a change, it just tells git to track the file.   
+
* 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 said changes in order to 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.   
  
==== Example ====
+
==== Examples ====
To add a file to git:
+
To stage a file/folder for the next commit (and/or add a new file):
 
* <code>git add <myfile></code>
 
* <code>git add <myfile></code>
 +
To commit all of the staged files/folders in the current folder to git:
 +
* <code>git commit</code>
 +
To commit all changes to "tracked" files/folders in the directory to git (bypassing the "add" staging):
 +
* <code>git commit -a </code>
  
 
==== References ====
 
==== References ====
 
* Guide: https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository
 
* Guide: https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository
 
* Manual: http://git-scm.com/docs/git-add
 
* Manual: http://git-scm.com/docs/git-add
 +
 +
==== 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.
  
 
== Create a local branch ==
 
== Create a local branch ==

Revision as of 20:38, 29 July 2015

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.

  • In general, you might want to have several separate branches of the repository built simultaneously on your machine. For example, you may want to have a program running off of "VersionA" and meanwhile develop code separately on "VersionB." To do this, you need multiple clones of the repository.

Examples

To create a clone of the master repository into the directory <mydir>:

References

Adding files and/or Committing changes to git

  • 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 said changes in order to 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.

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):

  • 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.

Create a local branch

    • cd sim-recon
    • git branch my_work
  1. Check-out the new branch
    • git checkout my_work