Difference between revisions of "Guide to Using Git"
(→Removing files from git) |
|||
Line 60: | Line 60: | ||
=== Examples === | === Examples === | ||
− | + | To remove <myfile> from git: | |
<pre> | <pre> | ||
git rm <myfile> | git rm <myfile> | ||
Line 69: | Line 69: | ||
* 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-rm | * Manual: http://git-scm.com/docs/git-rm | ||
+ | |||
+ | = Remote Repositories = | ||
+ | * The "origin" remote repository is the repository that you cloned when you initialized your setup with <span style="color:red">"git clone."</span> | ||
+ | |||
+ | === Examples === | ||
+ | |||
+ | To list the remote repositories that your clone is connected to | ||
+ | <pre> | ||
+ | git remote -v | ||
+ | </pre> | ||
= Create a local branch = | = Create a local branch = |
Revision as of 12:43, 30 July 2015
Contents
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
- Guide: https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository
- Manual: http://git-scm.com/docs/git-clone
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: similar to "svn commit"):
git commit -a
References
- Guide: https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository
- 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.
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 <myfile> from git:
git rm <myfile> git commit
References
- Guide: https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository
- Manual: http://git-scm.com/docs/git-rm
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
Create a local branch
-
cd sim-recon
-
git branch my_work
-
- Check-out the new branch
-
git checkout my_work
-