Posted in Uncategorized

Reminder on how to Perform Basic Git operations on Github-code (using command lines)


This blog is a summary of a way of setting up an environment to use git and checking in code. It assumes you have used a form of source control. If you are a total newbie to programming, try this first – https://try.github.io/levels/1/challenges/1
This blog uses an application called restaurant listing application (https://github.com/ChicagoVeg/restaurantList) for demonstration purposes. Change references to this to suit your needs.

Pre-requisites

  1. Download git: http://git-scm.com/download
  2. Create a repository in github. Go to your github page and click on the Repository-button.

Steps Up Environment

        1. Create a directory on your local drive, where you want the code.
        2. Go to PowerShell or Command Prompt or some other command line application that supports git; and go to the directory from Step #1
        3. In the prompt, type in (to set up directory to be a local git repo):
          git init
        4. Get the code (you will find the URL in the github page, under “HTTPS clone URL”, on the right-hand-side):
          git remote add origin https://github.com/ChicagoVeg/restaurantList.git
        5. Create a master branch
          git checkout -t -b master origin/master
        6. Track changes
          git branch --set-upstream-to=origin/master

Notes

        • If you get an issue where a path name is too long, run this command:
          git config --system core.longpaths true
        • If you get an error where there is no tracking information (means you skipped this step above), run this:
          git branch --set-upstream master origin/master

Checking in Code

      1. Get the code onto your local repo. Reminder, git is about each user having their local repo (for your own changes) and everyone sharing a group-repo (cumulative code one or more people shared)
        git pull
      2. Tracking untracked files (Adding new files to your local repo)
        To untracked files (files not already in github) to the commit package, use this:
        git add .
        Note: This add all untracked files. If you want to add specific files, adjust ths. See this for more more information: https://www.kernel.org/pub/software/scm/git/docs/git-add.html.
      3. Here is a way of committing changes to your local repo:
        git commit -am "This is some comment Fixed #4"Note: (1)This will NOT check in the code to the main repository for others to use. It commits it to your local, which you can later check in for others to use. The push command does the check in and that will be discusses later. (2)This is unnecessary if you have no newly added files. (3)In “-am”, the ‘a’ stands adds all changes while the ‘m’ is for commenting. This is not appropriate if you do not want to add all recent changes to your local repository. Use a different option for commit as suites your needs. (4)The “#4” in the commit associated the check-in to an issue number. It can be left out the comment if you are not associating the commit to an issue. Although I advise to always associate check-ins to something.
      4. To submit code from your local repo to the shared repo, use this command:
        git push
        Note: This pulls from your local repository and pushed it to github.

A tutorial with less verbose than this can be found here: http://davidgiard.com/2016/01/30/MyCommonGitCommands.aspx

Advertisements

Author:

I am a Developer. Studying Michael Jackson and poking around with Bioinformatics are my hobbies. I am based in Chicago, IL USA.

One thought on “Reminder on how to Perform Basic Git operations on Github-code (using command lines)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s