Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Useful Git commands

Antonio Ulloa edited this page Jan 13, 2015 · 9 revisions

Below you will find a set of Git commands that are relevant to maintaining the LSNM GitHub repository. For a more detailed description of the commands listed below, please refer to Scott Chacon's Pro Git Book.

How to grab a copy of the LSNM repository using command line Git

The following command downloads a copy of the LSNM repository to your local system (a.k.a "cloning a repository"):

$ git clone https://github.com/NIDCD/lsnm.git

Please note that the previous command will create a directory called "lsnm" in your current directory so any other directory previously named "lsnm" and located in the same directory might (will) be overwritten!

How to retrieve new work done by other people from the repository:

$ cd lsnm
$ git fetch origin

where origin has been defined as:

$ git remote add origin git@github.com:NIDCD/lsnm.git

How to show a list of remotes:

$ git remote -v

How to combine or "merge" changes made by other people to the repo wih your own changes

$ git merge origin

How to do "fetch" and "merge" at the same time

$ git pull origin master

How to inporate changes you made locally to the LSNM github repository

You have to use "pull-then-push" approach, which means you have to pull changes from the repository in order to merge them with you local changes and then push the changes back to the repository (don't forget to commit your local changes first!):

$ git pull origin master
$ git push origin master

The following basic commands are useful to keep track of changes to the LSNM software:

To show the status of changes to the code:

$ git status 

To commit a file that has been modified or recently created (it skips the 'staging' area):

$ git commit -a -m 'include a relevant comment here'

To rename a file that is currently being tracked:

$ git mv old_file_name new_file_name

To erase a file (physically and from the tracking system):

$ git rm file_not_needed

To add a new (existing) file or directory to the tracking system:

$ git add file_name

To add all new (untracked) files to the tracking system:

$ git add -A

To invoke a GUI that shows you history of changes to the code

$ gitk

To use git on a GUI interface rather than on the command line, use the following command:

$ git gui

To initialize git in current directory (you only need to do this once at the very beginning and when you need to start from scratch):

$ git init

To change editor used in git:

$ git config --global core.editor emacs

To declare your name in the git version control system (you only need to this once and git with label changes you make with YOUR name declared here):

$ git config --global user.name "John Doe"

To declare your email address (for labeling purposes only):

$ git config --global user.email "john.doe@nih.gov"

How to clone a git repository in preparation to put it on a git server:

$ git clone --bare LSNM LSNM.git

How to push changes to the repository on the server:

$ git push origin master

The following is an example screenshot of the gitk application, which allows you to visulalize the history of changes/updates to the LSNM directory:

Clone this wiki locally