Skip to content

Git Notes Miscellaneous

Randy McDermott edited this page Jul 20, 2016 · 11 revisions

This wiki give explains how to perform various tasks using git. Notes giving an overview for how to use git to manage the FDS-SMV project are found here.

Repository Properties

Showing repository properties

git config --list

Setting user name and email address

Before making a commit you need to tell git your user name and email address. The user name and email address should be what you use at github.com . Run the following commands on each system where you have a git repository.

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

git config --global user.email [email protected]

This information can be also defined in a bash startup shell (on a Linux or MAC system)

Set the executable file property using a git command

git update-index --chmod +x file

Turn coloring on

git config --global --add color.ui true

Set the executable file property using a Linux/OSX command

chmod +x file

Using SSH to access github from a PC

You need to define the GIT_SSH environment variable to point to the ssh application your are using on the PC. If you are using Putty, define GIT_SSH to point to plink.exe .

Examining the Repository

  • what files have changed (candidates to be committed)

    git status

    git status -uno (do not show untracked files)

  • getting log of changes

    git log path_to_directory (or . for current directory)

    git log --graph

Manipulating the Repository

  • bring local repository up to date (with respect to a remote repository)

    git fetch (updates the local repository)

    git merge (merges changes from local repository into working files)

    git pull (git fetch + git merge)

  • add file to working tree

    git add file

  • remove file from working tree

    git remove file

  • compare local changes to your last commit

    git diff HEAD (what you would be committing if you run "git commit -a")

  • reverting changes to working copy of a file(s)

    git checkout file(s)

  • More generally, suppose you have modified and committed changes to a file but you want to purge these and go back to the version of the file in a different repo/branch, do

    git checkout repo_name/branch_name -- filename

  • It is sometimes handy to completely throw out the files in a certain directory, download a clean set of files from the repo, and do a build; we do this often, for example, when testing the manuals. Suppose you do rm * (cautiously) within the manual directory to purge all the auxiliary files, etc.; you can get the clean .tex and .sh files back by

    git checkout HEAD .

    The period indicates the current directory and below.

  • cleaning the repository

To remove all untracked files use:

`git clean -dxf`

To revert files back to previous revision use:

`git add .`

`git reset --hard HEAD`
  • change to a different "revision"

    git checkout revision_string (do git log to get revision_string blob)

  • change back to latest "revision".

    git pull upstream master (need to have set up upstream tracking branch master)

  • committing files

    git commit files -m "commit message" (commit changes to local repository) git push (push changes up to a remote repository)

    or

    git status

    git add -u (this adds only the modified files seen from git status)

    git commit -m "commit message"

    git push repo_name branch_name

Branching

  • What Branches are present

    git branch

  • Creating a Branch

    git branch new_branch (be careful not to use "branch" to try to switch branches!)

  • Pruning branches

    git remote prune origin one time

    git config fetch.prune true every time

  • Checkout and track a remote branch that does not yet exist locally

    git checkout -b test repo_name/test (repo name is usually origin)

  • Compare two branches - handy before doing a push or pull

    git diff repo1\branch1 repo2\branch2

    git diff repo1\branch1..repo2\bransh2 path/to/directory_or_file

    Drop repo to compare a local branch.

  • Delete a local branch

    git branch -d <branch_name>

  • Delete a remote branch

    git push remote_name --delete <remote_branch_name>

  • Track a local branch with a remote branch

    git branch --track local_branch_name remote_name remote_branch_name

  • Switching Branches

    git checkout branch_name

  • Merging Branches

    to merge changes from branch_from into branch_to

    git checkout branch_to

    git merge branch_from

  • Find common ancestor of two branches

    git merge-base branch_1 branch_2

Creating Git Aliases

You will eventually get comfortable with the commands you use frequently and may want a shortcut. For example, if you frequently use

$ git status -uno

you could add a Git alias for that command like so

$ git config --global alias.st 'status -uno'

Now, you can simply type $ git st to see the status sans-untracked files.

Checking Out GoogleCode Subversion Revisions

In June 2015, the FDS-SMV project moved from GoogleCode to GitHub, and switched from SVN to Git as its revision control system. The commit log of the project while it was hosted under GoogleCode from January 2007 to June 2015 is stored in a text file located here. Note that the file might be too large to display in the GitHub browser (the easiest way to get this file is to clone the repo). To determine the Git hash corresponding to a particular SVN revision number, first find the commit message corresponding to the SVN revision number in the GoogleCode commit log. For example, the commit message for r22995 is "adding time average output option in fds2ftmi". The Git hash corresponding to this SVN commit can be found as follows:

$ git log --grep='adding time average'
commit a5d22ac75bc4ded09ce26007efb2e7a6d026d540
Author: RIO4FDS <[email protected]>
Date:   Fri Jun 26 13:44:45 2015 +0000|
    adding time average output option in fds2ftmi 

You can now checkout that particular revision of the repository:

$ git checkout a5d22ac

Note that it is sufficient to use as few as 7 characters to uniquely identify the hash.

Clone this wiki locally