<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.ccn.ucla.edu/wiki/index.php?action=history&amp;feed=atom&amp;title=Setting_Up_and_Using_Git</id>
	<title>Setting Up and Using Git - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.ccn.ucla.edu/wiki/index.php?action=history&amp;feed=atom&amp;title=Setting_Up_and_Using_Git"/>
	<link rel="alternate" type="text/html" href="https://www.ccn.ucla.edu/wiki/index.php?title=Setting_Up_and_Using_Git&amp;action=history"/>
	<updated>2026-05-06T17:52:49Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://www.ccn.ucla.edu/wiki/index.php?title=Setting_Up_and_Using_Git&amp;diff=1244&amp;oldid=prev</id>
		<title>Ccn admin: 23 revisions</title>
		<link rel="alternate" type="text/html" href="https://www.ccn.ucla.edu/wiki/index.php?title=Setting_Up_and_Using_Git&amp;diff=1244&amp;oldid=prev"/>
		<updated>2014-01-16T03:42:34Z</updated>

		<summary type="html">&lt;p&gt;23 revisions&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Introduction=&lt;br /&gt;
[http://git-scm.com/ GIT]  is a decentralized version control system. This differs from CVS, SVN, and various other VCS&amp;#039;s in that there is no need for a central repository though one can be used if desired. All working directories are self contained and complete projects in their own right. In the dynamic collaboration environments typically found in research and open source communities this is particularly appealing. It is suited for small projects and very large projects alike and is extremely fast for either. Further, branching and merging (often a royal pain in other version control environments) are first class citizens. They are the natural way to make changes. Typical work flow involves branching, then merging with the trunk all in the course of one session.&lt;br /&gt;
&lt;br /&gt;
 This is NOT a complete git tutorial. It&amp;#039;s only a quick walk through and is not intended to be either exhaustive in even the loosest sense of the word.&lt;br /&gt;
&lt;br /&gt;
For full information on Git please see the [http://git-scm.com/ GIT home site] or any of the many, many tutorials found with a simple google search.&lt;br /&gt;
&lt;br /&gt;
=Windows=&lt;br /&gt;
[http://git-scm.com/ GIT] is primarily designed for UNIX based systems. Specifically, it was written by Linus Torvalds as a BitKeeper replacement for the linux kernel project. There is a [http://code.google.com/p/msysgit/ Windows client], however this tutorial focuses on installation via Cygwin. Not because I view it as superior, I have no experience with the windows client to make a fair comparison, but because it is what I am most familiar and comfortable with.&lt;br /&gt;
&lt;br /&gt;
==Installing CygWin + GIT==&lt;br /&gt;
Installing [http://www.cygwin.com/ Cygwin] couldn&amp;#039;t be simpler. &lt;br /&gt;
&lt;br /&gt;
*Download the [http://www.cygwin.com/setup.exe Setup.exe]&lt;br /&gt;
*Double click for installation&lt;br /&gt;
*Accept the defaults until you reach the package selection screen&lt;br /&gt;
*Select the following packages (if you click &amp;#039;View&amp;#039; until it is set to &amp;#039;Full&amp;#039;, you get an alphabetized list)&lt;br /&gt;
**openssl&lt;br /&gt;
**openssh&lt;br /&gt;
**git&lt;br /&gt;
**git-gui (graphical front end for git, basic but alright)&lt;br /&gt;
*Click next and watch the pretty color bars move to the left.&lt;br /&gt;
&lt;br /&gt;
 If you ever want to add or update packages to cygwin, you just rerun the setup. It&amp;#039;ll auto-detect a previous install and run in update/upgrade mode.&lt;br /&gt;
&lt;br /&gt;
=OS X=&lt;br /&gt;
First, install [http://www.macports.org/ MacPorts]. Their documentation is thorough and complete, so the process is not repeated here. Next, issue the following commands&lt;br /&gt;
 $ sudo port selfupdate&lt;br /&gt;
 $ sudo port install git-core&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it, you&amp;#039;re done. &lt;br /&gt;
&lt;br /&gt;
==Help! I got a &amp;#039;command not found: port&amp;#039; error!==&lt;br /&gt;
You skipped the MacPorts installation instructions didn&amp;#039;t you? *hint* check the part about modifying your PATH.&lt;br /&gt;
&lt;br /&gt;
=Using Public/Private Keys with GIT=&lt;br /&gt;
GIT operates over SSH and it&amp;#039;s very common to use public/private key authentication for interacting with remote repositories. This section walks you through creating these keys, setting up a ssh config entry for the repository, and doing a quick &amp;quot;clone, branch, change, merge, push&amp;quot; cycle. This is a typical development cycle.&lt;br /&gt;
&lt;br /&gt;
==Creating public/private keys==&lt;br /&gt;
For more information on public/private key authentication please see [http://www.ibm.com/developerworks/library/l-keyc.html IBM&amp;#039;s] tutorial. The following command initiates the creation of a DSA public/private key pair. &lt;br /&gt;
 $ ssh-keygen -t dsa&lt;br /&gt;
&lt;br /&gt;
This walks you through a series prompts, the first of which is:&lt;br /&gt;
 $ ssh-keygen -t dsa&lt;br /&gt;
 Generating public/private dsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/home/James/.ssh/id_dsa): &lt;br /&gt;
Since we&amp;#039;re creating a pub/priv key for git, let&amp;#039;s save the key as &amp;quot;git_dsa&amp;quot;. Then you are then prompted for a password. Choose a decent password for your new key.&lt;br /&gt;
&lt;br /&gt;
 Enter file in which to save the key (/home/James/.ssh/id_dsa): /home/James/.ssh/git_dsa&lt;br /&gt;
 Created directory &amp;#039;/home/James/.ssh&amp;#039;.&lt;br /&gt;
 Enter passphrase (empty for no passphrase): &lt;br /&gt;
 Enter same passphrase again:  &lt;br /&gt;
 Your identification has been saved in /home/James/.ssh/git_dsa.&lt;br /&gt;
 Your public key has been saved in /home/James/.ssh/git_dsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 1f:d8:9b:9f:69:94:3d:ed:bc:cc:62:0f:18:2b:6a:34 James@James-PC&lt;br /&gt;
 The key&amp;#039;s randomart image is:&lt;br /&gt;
 +--[ DSA 1024]----+&lt;br /&gt;
 |                 |&lt;br /&gt;
 |                 |&lt;br /&gt;
 |                 |&lt;br /&gt;
 |         o       |&lt;br /&gt;
 |        S o. o . |&lt;br /&gt;
 |       E . +* o .|&lt;br /&gt;
 |      . ..++ . + |&lt;br /&gt;
 |       .. ...=+ o|&lt;br /&gt;
 |      ..   .= o=.|&lt;br /&gt;
 +-----------------+&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that we gave the full path to the new key and the ~/.ssh directory is created for us. &lt;br /&gt;
That&amp;#039;s all there is to creating a key.&lt;br /&gt;
&lt;br /&gt;
==Setting up the ssh config file==&lt;br /&gt;
This is covered in great detail in the [[Creating_SSH_Shortcuts_Using_SSH_Config]] tutorial on the [[HowTo_Pages]], so here we&amp;#039;ll just show a typical configuration for a git host.&lt;br /&gt;
Open up your ~/.ssh/config with your favorite text editor and create the following entry:&lt;br /&gt;
&lt;br /&gt;
 Host git&lt;br /&gt;
     Hostname mygit.host.com&lt;br /&gt;
     User gituser&lt;br /&gt;
     IdentityFile /home/James/.ssh/git_dsa&lt;br /&gt;
     &lt;br /&gt;
Notice that we&amp;#039;ve specified the key to use with the full path to our git_dsa created in the previous step.&lt;br /&gt;
===Important!===&lt;br /&gt;
If this is your first time creating a .ssh/config file you likely need to correct the permissions. This is done by&lt;br /&gt;
 $ chmod 600 ~/.ssh/config&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Giving out public key to the git host==&lt;br /&gt;
The final step to gain access is giving our *public* key to the git host. It is very important that you only give your *public* key (this is the file ending in .pub). You should &amp;lt;b&amp;gt;never&amp;lt;/b&amp;gt;, &amp;lt;b&amp;gt;ever&amp;lt;/b&amp;gt;, not even on threat of having to watch endless repeats of Family Ties for the rest of your life give &amp;lt;i&amp;gt;anyone&amp;lt;/i&amp;gt; your private key file.&lt;br /&gt;
&lt;br /&gt;
You can do this via email, or scp if you own the account you&amp;#039;re using the key for. If you control the host/account you wish to log into simply copy the contents of the git_dsa.pub into the ~/.ssh/authorized_keys file. If it does not exist, create it.&lt;br /&gt;
&lt;br /&gt;
Then you can log in via:&lt;br /&gt;
&lt;br /&gt;
 $ ssh git&lt;br /&gt;
&lt;br /&gt;
==Using SSH Agent for single password==&lt;br /&gt;
===Windows/Cygwin PreRequisite===&lt;br /&gt;
On windows there are a few extra steps, but we&amp;#039;re used to that by now. First, we need to modify our ~/.bashrc to contain the following (thank you [http://www.webweavertech.com/ovidiu/weblog/archives/000326.html Web Weaver Tech]):&lt;br /&gt;
&lt;br /&gt;
 export SSH_AUTH_SOCK=/tmp/.ssh-socket&lt;br /&gt;
 ssh-add -l 2&amp;gt;&amp;amp;1 &amp;gt;/dev/null&lt;br /&gt;
 if [ $? = 2 ]; then&lt;br /&gt;
    # Exit status 2 means couldn&amp;#039;t connect to ssh-agent; start one now&lt;br /&gt;
    ssh-agent -a $SSH_AUTH_SOCK &amp;gt;/tmp/.ssh-script&lt;br /&gt;
    . /tmp/.ssh-script&lt;br /&gt;
    echo $SSH_AGENT_PID &amp;gt;/tmp/.ssh-agent-pid&lt;br /&gt;
 fi&lt;br /&gt;
 function kill-agent {&lt;br /&gt;
    pid=`cat /tmp/.ssh-agent-pid`&lt;br /&gt;
    kill $pid&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Next, enter the following in your environment variables (Control Panel =&amp;gt; System =&amp;gt; Advanced Settings =&amp;gt; Environment Variables):&lt;br /&gt;
&lt;br /&gt;
 NAME: SSH_AUTH_SOCK&lt;br /&gt;
 VALUE: /tmp/.ssh-socket&lt;br /&gt;
&lt;br /&gt;
After this, the standard directions below should work for you.&lt;br /&gt;
&lt;br /&gt;
===All Other Platforms===&lt;br /&gt;
You may notice you still have to use a password to login, so why all the trouble of creating a public/private key? Well, actually, with the SSH Agent you only need to enter your password once. There is a fix for this though. Upon opening terminal, issue the following command&lt;br /&gt;
&lt;br /&gt;
 $ ssh-add ~/.ssh/git_dsa&lt;br /&gt;
&lt;br /&gt;
Where &amp;#039;git_dsa&amp;#039; is the name of the key you wish to add. You can add as many as you like and, obviously, the names may differ. After entering your password, you&amp;#039;ll be able to log into any host using this key without a pass for as long as you&amp;#039;re logged in. If using our previous host example, we would clone a project called &amp;quot;Foo&amp;quot; by using the full path to the project. &lt;br /&gt;
&lt;br /&gt;
==Cloning a project over ssh==&lt;br /&gt;
Now we can fetch projects from our git user. If you were on windows, I know it feels like a lot of work. But we&amp;#039;re almost there!&lt;br /&gt;
&lt;br /&gt;
 $ git clone ssh://git/full/path/too/Foo.git &lt;br /&gt;
&lt;br /&gt;
From there on out, it&amp;#039;s standard git management.&lt;br /&gt;
&lt;br /&gt;
=Git Work Flow=&lt;br /&gt;
This is just a quickie run through of a git work flow. We&amp;#039;re going to assume you&amp;#039;ve cloned a git project named Foo.&lt;br /&gt;
&lt;br /&gt;
==Create and Checkout a Working Branch==&lt;br /&gt;
As mentioned before, branching is a first class citizen. Before we make any changes, let&amp;#039;s create a working branch. We&amp;#039;ll call it &amp;quot;development&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 $ git branch development&lt;br /&gt;
&lt;br /&gt;
To see our branches, execute the branch command with no arguments. &lt;br /&gt;
 $ git branch&lt;br /&gt;
     development&lt;br /&gt;
  * master&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;master&amp;#039; branch is the default main branch. The development branch is the one we just created. The &amp;#039;*&amp;#039; prepended to the master indicates this is the branch we&amp;#039;re currently in.&lt;br /&gt;
&lt;br /&gt;
To actually &amp;lt;i&amp;gt;use&amp;lt;/i&amp;gt; the development branch, we must first check it out&lt;br /&gt;
&lt;br /&gt;
 $ git checkout development&lt;br /&gt;
&lt;br /&gt;
Now we see the &amp;#039;*&amp;#039; by development&lt;br /&gt;
 $ git branch&lt;br /&gt;
 *  development&lt;br /&gt;
     master&lt;br /&gt;
&lt;br /&gt;
The above two steps can be condensed into a single step by:&lt;br /&gt;
 $ git checkout -b development&lt;br /&gt;
&lt;br /&gt;
This means &amp;#039;checkout the development branch and create it if it doesn&amp;#039;t exist&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
==Modify Files and Commit changes==&lt;br /&gt;
Open a file and make some trivial change and close it. In this case, I modify a file called &amp;quot;temp&amp;quot;.  Now let&amp;#039;s commit our changes:&lt;br /&gt;
&lt;br /&gt;
 $ git commit -a -m &amp;quot;Edited the temp file&amp;quot;&lt;br /&gt;
 Created commit c75b3d3: Edited the temp file&lt;br /&gt;
 1 files changed, 3 insertions(+), 0 deletions(-)&lt;br /&gt;
&lt;br /&gt;
*-a commits all changes&lt;br /&gt;
*-m says we&amp;#039;re going to enter the comment inline. otherwise a text editor is opened for the commit comment.&lt;br /&gt;
&lt;br /&gt;
==Merge development with master==&lt;br /&gt;
In git, we merge by &amp;quot;pulling&amp;quot; from one branch to another. So to merge with the master branch, we first check out master than &amp;#039;pull&amp;#039; development into it.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout master&lt;br /&gt;
 $ git pull . development&lt;br /&gt;
 From .&lt;br /&gt;
  * branch            development -&amp;gt; FETCH_HEAD&lt;br /&gt;
 Updating 6d26cca..c75b3d3&lt;br /&gt;
 Fast forward&lt;br /&gt;
  temp |    3 +++&lt;br /&gt;
  1 files changed, 3 insertions(+), 0 deletions(-)&lt;br /&gt;
&lt;br /&gt;
If you check the temp file, you&amp;#039;ll see our changes are available. If there were any conflicts you&amp;#039;d be prompted to resolve them. The process should be familiar to anyone used to version control. Since we no longer need it, we can delete the development branch if we wish&lt;br /&gt;
&lt;br /&gt;
 $ git branch -d development&lt;br /&gt;
 Deleted branch development.&lt;br /&gt;
&lt;br /&gt;
==Send Our Changes to the Main Repository==&lt;br /&gt;
All of the steps above only modify our &amp;lt;i&amp;gt;local repository&amp;lt;/i&amp;gt;. They have absolutely no effect on the main repository we cloned earlier. If we wish to send these changes upstream we &amp;quot;push&amp;quot; our changes. &lt;br /&gt;
&lt;br /&gt;
But before we do this, we need to catch up to any changes that other developer&amp;#039;s may have made with our remote repository. To do this, we should do a git [http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html rebase]. &lt;br /&gt;
&lt;br /&gt;
 $ git rebase origin&lt;br /&gt;
&lt;br /&gt;
This will &amp;quot;sync&amp;quot; our two repositories. Technically, it first rewinds the commits we&amp;#039;ve made locally, pulls the remote commits, then replays our local commits on top of them. Again, resolve any conflicts that need resolving.&lt;br /&gt;
 &lt;br /&gt;
 Pushing of changes should *only* be done on bare repositories. If another developer wants your changes, they should &amp;quot;pull&amp;quot; from your repository into theirs.&lt;br /&gt;
&lt;br /&gt;
Finally,&lt;br /&gt;
&lt;br /&gt;
 $ git push origin master&lt;br /&gt;
&lt;br /&gt;
=Alternate Git Work Flow (working with a remote development branch)=&lt;br /&gt;
This walks through working with a remote development branch (instead of merging a local branch into master).&lt;br /&gt;
&lt;br /&gt;
==List remote branches==&lt;br /&gt;
 $ git branch -r &lt;br /&gt;
&lt;br /&gt;
You&amp;#039;ll get output similar to this (assuming the remote is named &amp;quot;origin&amp;quot;)&lt;br /&gt;
  origin/HEAD -&amp;gt; origin/master&lt;br /&gt;
  origin/dev&lt;br /&gt;
  origin/development&lt;br /&gt;
  origin/master&lt;br /&gt;
&lt;br /&gt;
==Checkout the remote branch==&lt;br /&gt;
 $ git checkout -b development origin/development&lt;br /&gt;
&lt;br /&gt;
This will create a local branch named development that is a clone of the remote branch development on origin.&lt;br /&gt;
&lt;br /&gt;
===Checking out a remote branch with tracking===&lt;br /&gt;
&lt;br /&gt;
You can also check out a remote branch with tracking. Tracking &amp;quot;links&amp;quot; a branch with a specific remote branch. The benefit is &lt;br /&gt;
that you no longer have to specific the remote branch when pulling, rebasing, or pushing changes.&lt;br /&gt;
&lt;br /&gt;
So, instead of:&lt;br /&gt;
 $ git push origin development&lt;br /&gt;
Or:&lt;br /&gt;
 $ git rebase origin development&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;d simply have to do:&lt;br /&gt;
&lt;br /&gt;
 $ git rebase&lt;br /&gt;
 $ git push&lt;br /&gt;
&lt;br /&gt;
To check out a remote branch with tracking:&lt;br /&gt;
&lt;br /&gt;
 $ git branch --track development origin/development &amp;amp;&amp;amp; git checkout development&lt;br /&gt;
&lt;br /&gt;
==Rebase the development branch==&lt;br /&gt;
Next, you [http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html rebase] against the remote development branch, this is pretty much the same as the previous example except we must specify the remote branch name&lt;br /&gt;
&lt;br /&gt;
 $ git rebase origin/development&lt;br /&gt;
&lt;br /&gt;
Again, resolve any conflicts that might occur.&lt;br /&gt;
&lt;br /&gt;
==Push our changes to the central repository==&lt;br /&gt;
 $ git push origin development&lt;br /&gt;
&lt;br /&gt;
=External Links=&lt;br /&gt;
*[http://git-scm.com/ GIT]&lt;br /&gt;
*[http://www.cygwin.com/ Cygwin]&lt;br /&gt;
*[http://www.macports.org/ MacPorts]&lt;br /&gt;
*[http://www.ibm.com/developerworks/library/l-keyc.html IBM Public/Private Key Tutorial]&lt;/div&gt;</summary>
		<author><name>Ccn admin</name></author>
	</entry>
</feed>