Showing posts with label github. Show all posts
Showing posts with label github. Show all posts

Wednesday, December 3, 2014

Git: Installation on Ubuntu

Installation


Installing Git on Ubuntu 14.04; open a terminal window and type:
 sudo apt-get install git  


Operational Output

 craigtrim@CVB:~$ sudo apt-get install git  
 [sudo] password for craigtrim:   
 Reading package lists... Done  
 Building dependency tree      
 Reading state information... Done  
 The following extra packages will be installed:  
  git-man liberror-perl  
 Suggested packages:  
  git-daemon-run git-daemon-sysvinit git-doc git-el git-email git-gui gitk  
  gitweb git-arch git-bzr git-cvs git-mediawiki git-svn  
 The following NEW packages will be installed:  
  git git-man liberror-perl  
 0 upgraded, 3 newly installed, 0 to remove and 241 not upgraded.  
 Need to get 3,274 kB of archives.  
 After this operation, 21.6 MB of additional disk space will be used.  
 Do you want to continue? [Y/n] Y  
 Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty/main liberror-perl all 0.17-1.1 [21.1 kB]  
 Get:2 http://us.archive.ubuntu.com/ubuntu/ trusty/main git-man all 1:1.9.1-1 [698 kB]  
 Get:3 http://us.archive.ubuntu.com/ubuntu/ trusty/main git amd64 1:1.9.1-1 [2,555 kB]  
 Fetched 3,274 kB in 3s (1,009 kB/s)  
 Selecting previously unselected package liberror-perl.  
 (Reading database ... 168600 files and directories currently installed.)  
 Preparing to unpack .../liberror-perl_0.17-1.1_all.deb ...  
 Unpacking liberror-perl (0.17-1.1) ...  
 Selecting previously unselected package git-man.  
 Preparing to unpack .../git-man_1%3a1.9.1-1_all.deb ...  
 Unpacking git-man (1:1.9.1-1) ...  
 Selecting previously unselected package git.  
 Preparing to unpack .../git_1%3a1.9.1-1_amd64.deb ...  
 Unpacking git (1:1.9.1-1) ...  
 Processing triggers for man-db (2.6.7.1-1) ...  
 Setting up liberror-perl (0.17-1.1) ...  
 Setting up git-man (1:1.9.1-1) ...  
 Setting up git (1:1.9.1-1) ...  



Setting your Username and Email

Git uses your username to associate commits with an identity.

The git config command can be used to change your Git configuration, including your username. It takes two arguments:
 craigtrim@CVB:~$ git config --global user.name "craigtrim"  
 craigtrim@CVB:~$ git config user.name  
 craigtrim  
Notice how I was able to confirm the setting in the second line. Also, by using the -global flag, I've set this for every repository on the computer.

I also want to set the email:
 git config --global user.email "craigtrim@gmail.com"  



Cloning a Remote Repository

I want to get a copy of the SWTK commons project so I can look at the code. I'm going to clone the repository in Git. You simply First i'll create a directory for the contents
 mkdir -p $WS/swtk/commons  
 cd $WS/swtk/commons  

Then I'm going to set up a remote which tells Git where the repository is
 git remote add commons https://github.com/torrances/swtk-common.git  

then clone
 git clone https://github.com/torrances/swtk-common.git  

Operational Output

 craigtrim@CVB:~/workspace/swtk/commons$ git remote add commons https://github.com/torrances/swtk-common.git  
 craigtrim@CVB:~/workspace/swtk/commons$ git clone https://github.com/torrances/swtk-common.git  
 Cloning into 'swtk-common'...  
 remote: Counting objects: 770, done.  
 remote: Compressing objects: 100% (139/139), done.  
 remote: Total 770 (delta 44), reused 0 (delta 0)  
 Receiving objects: 100% (770/770), 1.57 MiB | 975.00 KiB/s, done.  
 Resolving deltas: 100% (264/264), done.  
 Checking connectivity... done.  
 craigtrim@CVB:~/workspace/swtk/commons$ ls -lah swtk-common/  
 total 36K  
 drwxrwxr-x 9 craigtrim craigtrim 4.0K Dec 3 17:53 .  
 drwxrwxr-x 4 craigtrim craigtrim 4.0K Dec 3 17:53 ..  
 drwxrwxr-x 2 craigtrim craigtrim 4.0K Dec 3 17:53 build  
 drwxrwxr-x 3 craigtrim craigtrim 4.0K Dec 3 17:53 dependencies  
 drwxrwxr-x 3 craigtrim craigtrim 4.0K Dec 3 17:53 docs  
 drwxrwxr-x 8 craigtrim craigtrim 4.0K Dec 3 17:53 .git  
 drwxrwxr-x 5 craigtrim craigtrim 4.0K Dec 3 17:53 org.swtk.common.core  
 drwxrwxr-x 7 craigtrim craigtrim 4.0K Dec 3 17:53 org.swtk.common.data  
 drwxrwxr-x 5 craigtrim craigtrim 4.0K Dec 3 17:53 org.swtk.common.mysql  
 -rw-rw-r-- 1 craigtrim craigtrim  0 Dec 3 17:53 README.md    



References

  1. https://help.github.com/articles/setting-your-username-in-git/
    1. Setting your username in Git
  2. [YouTube] How to Install and Configure Git & Repositorys on GitHub
  3. Cloning a Remote Repository using Git

Monday, December 1, 2014

Git: Cloning a Remote Repository

Assumptions

  1. A remote GIT repository exists
  2. I want to use the project with Eclipse
  3. I want a “projects” sub-directory that does not contain Eclipse meta-data


Command Sequence

  1. mkdir shortname
  2. cd shortname
  3. git init
  4. git remote add shortname url
  5. git clone url
  6. git pull -u shortname
  7. mkdir projects
  8. cd projects
  9. mv shortname/ projects/
Open Eclipse and Import Projects! Reference “Git with Eclipse: Design Patterns”



Case Study: Clone SWTK Commons

  1. mkdir commons
  2. cd commons
  3. git init
  4. git remote add commons https://github.com/torrances/swtk-common.git
  5. git clone https://github.com/torrances/swtk-common.git
    1. Operational Output
    2.  craigtrim@W540 /c/Backup/Java/workspaces/swtk/commons (master)  
       $ git clone https://github.com/torrances/swtk-common.git  
       Cloning into 'swtk-common'...  
       remote: Counting objects: 737, done.  
       remote: Compressing objects: 100% (106/106), done.  
       remote: Total 737 (delta 17), reused 0 (delta 0)  
       Receiving objects: 100% (737/737), 1.57 MiB | 455.00 KiB/s, done.  
       Resolving deltas: 100% (237/237), done.  
       Checking connectivity... done.  
      
  6. git pull -u commons
  7. mkdir projects
  8. cd projects
  9. mv commons/ projects/



Troubleshooting

  1. Remote already exists
    1. The remote add command was already executed
    2. List existing remotes on the command line using remote -v
    3. Git Reference: Working with Remotes
  2. Git Repository Information not displayed in the Eclipse Package Overview
    1. This is not important. Git interaction should occur within the Git Shell; not within Eclipse. I do not recommend using the built-in Git plugin with Eclipse. Eclipse is useful as an IDE, but building should be handled externally (eg. via Maven) as well as repository interaction (via the Git command line).