Introduction to Git for Final Year Projects.

Quick introduction to Git for Final Year Projects, because the same questions seem to keep coming up.

  1. Download Git for Windows from: http://git-scm.com/download/win and install it.
  2. Open “Git Bash” from the start menu.
  3. Run the command
    ssh-keygen -t rsa -C "[email protected]"

    using your own email. It’s advised to leave all the options at the default (so just press enter every time it asks). This will create two files in C:/Users/<username>/.ssh/ id_rsa and id_rsa.pub.

  4. Open the id_rsa.pub and leave it open while your proceed.
  5. So the URL for the web interface is: https://csigit.ucd.ie/ so we’ll start with that. Login using your UCD Connect username and password. The username will be in the form [email protected]
  6. Go to Profile Settings. You can fill out your name when your here, but SSH Keys from the top is what we care about.
  7. There shouldn’t be anything here by default, so if there is, remove it.
  8. Copy and paste the key from id_rsa.pub that you opened previously, and add it.

This is enough to add the keys, but you need to specify the key every time you run a git command. There is a thing on linux called ssh-agent that keeps the private key in memory removing the need to specifify it at all, so to make it very easy to use, continue below.

  1. Create a new file called .bashrc in C:\Users\<username>\ and open it for editing. (this file is basically a script that is run every time the “Git Bash” prompt is opened)
  2. Add the following, and save it:
    env=~/.ssh/agent.env
    
    agent_is_running() {
        if [ "$SSH_AUTH_SOCK" ]; then
            ssh-add -l >/dev/null 2>&1 || [ $? -eq 1 ]
        else
            false
        fi
    }
    
    agent_has_keys() {
        ssh-add -l >/dev/null 2>&1
    }
    
    agent_load_env() {
        . "$env" >/dev/null
    }
    
    agent_start() {
        (umask 077; ssh-agent >"$env")
        . "$env" >/dev/null
    }
    
    if ! agent_is_running; then
        agent_load_env
    fi
    
    # if your keys are not stored in ~/.ssh/id_rsa.pub or ~/.ssh/id_dsa.pub, you'll need
    # to paste the proper path after ssh-add
    if ! agent_is_running; then
        agent_start
        ssh-add
    elif ! agent_has_keys; then
        ssh-add
    fi
    
    unset env
  3. So this basically checks if the “ssh-agent” program is running, and if not starts it – this just ensures you don’t have multiple copies running every time.
  4. Now close any open “Git Bash” prompts and open them again.

And you’re done. Now the private key it held in memory, all the git commands can be run very simply.

Now on to making your local copy of the project

  1. You can add a project using the Web Interface, and when done you can find the URL like [email protected]:12345678/projectname.git
  2. In “Git Bash” go to where you want you keep the local project and run:
    git clone [email protected]:12345678/projectname.git

    which will make a new folder called “projectname” with everything in it.

  3. Now you need to find a git tutorial:

This shows you how to commit your changes locally: https://www.atlassian.com/git/tutorials/saving-changes/git-commit

This shows you how to push you local commits to the remote repository https://www.atlassian.com/git/tutorials/syncing/git-push

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>