Git – GitHub – Private Repositories

Background

A bit over 4 years ago, I read Troy Hunt’s blog titled “The Ghost Who Codes: How Anonymity is Killing Your Programming Career“.

 

Troy Hunt – The Ghost Who Codes: How Anonymity is Killing Your Programming Career

It is available here.

And, here are all the places he looked for the anonymous programmer….

.

 

4 Years Later

It is 4 years later, enough time to go through college, and get a college degree.

In between signed up for free GitHub.

Private Repositories

It is now time to sign up for a paid version.

Why Private

The reasons are numerous and includes:

  1. Need for secured storage
    • Sometimes I have code that is not yet complete, but I will still like to save to a location other than my laptop
    • Occasionally have proprietary data such as credentials or server names that I will rather not share with the whole world
  2. Saving Things Online
    • Forces better coding practice
    • Structure
    • Succinct

 

Steps

To create private repositories, you need to pay monthly or yearly fees

Outline

  1. Sojourn to github
  2. Login to your Account or create a new one
  3. On the top new bar click on the + sign
  4. In the “New Repository” window
    • Enter the Repository Name
    • In the “Public or Private” Group box, Choose Private
    • Enter Credit Card Info

 

Screen Shots

Menu – New Repository

On the top menu bar, click on to + sign

Repository – Private

Choose to create a Private Repository…

 

Soul Searching

It is incredible how little it takes to encourage better Angels

  1. Linux Torvalds
    • Lord of the Files: How GitHub Tamed Free Software (And More)
      Link
  2. Troy Hunt
    • Troy Hunt web site
      Link

 

Dedicated

Dedicated to Troy Hunt

Image

 

Textual


02 June 2017

I’m in Belgium! After 35 hours of travel to Porto in Portugal then 2 days of workshop plus a user group there, I’m now in Leuven which is in the home of epic Belgium beer. I’m now into day 2 of another workshop here after having done a user group on Azure last night so it’s turning into a very long week. Not a lot of new stuff to talk about blog wise, but I share what it’s like doing these events and some of the things I learn along the way.

Git – Error – “git push” failing with error “Updates were rejected because the tip of your current branch is behind”

Background

Trying to update files in one of our public github repositories, but failing with the error message pasted below.

 

Command

Here is the simple command I ran:

git push

That command obviously succeeded git add and git commit.

 

Error

Image

tipofcurrentbranchisbehind-20170126-1014am

 

Textual

To https://github.com/DanielAdeniji/sp_ListObjectLevelPermissions.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘https://github.com/DanielAdeniji/sp_ListObjectLevelPermissions.git’
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.

Explanation

  1. Key Terms
    • error: failed to push some refs to
    • hint: Updates were rejected because the tip of your current branch is behind

 

Remediation

“Git Reset”

Source

Stack Overflow

What’s the best practice to “git clone” into an existing folder?
Link

stack-overflow-user1055643

 

Code



rem set gitURL
set _gitURL=https://github.com/DanielAdeniji/sp_ListObjectLevelPermissions.git

rem remove git folder
rmdir /S /Q .git 

rem git init
git init

rem git remote add origin to Git URL
git remote add origin %_gitURL%

rem git fetch
git fetch

rem git reset
git reset --mixed origin/master

Explanation

  1. Please replace the variable _gitURL with the your Git Repository

Output

gitreset-20170126-1057am

 

Summary

As always, nothing but the Internet saves.

Technical: Installing and Using GIT Command Line Interface on CentOS

Technical: Installing and Using GIT Command Line Interface on CentOS

Background

Now that my primary box is this CentOS Linux box, I need to make sure that I can share a bit on it.

With a web browser, I am able to post to wordpress.

And, I probably can look for a web interface to get to github, as well.  But, I really need to re-familiarize with Bash and command line stuff.

And, so I will stay away from nice, pretty GUI for now.  And, go shell.

 

Installation

On CentOS, we can install via the yum.

sudo yum install git-core

Yum install is easy as it takes care of installing all the dependant files.

 

Customize

 

Set User name

git config --global user.name "Daniel Adeniji"

Set email address


git config --global user.email "Daniel_Adeniji@nobody.com"

 

 

Create a repository

Connect to your github online account, and create a new repository

 

Identify local folder on host

On your Linux\Cent OS host, identify or create local folder that will serve as your working folder.

In our case, we will use /home/dadeniji/development/apache.org/tomcat/MSAdventureWorksDWDB.Public

 

Change Working Directory

Make identified folder your working directory

Launch Unix terminal and change working folder to identified folder.

Syntax:

cd <working-folder>

 

Sample

cd /home/dadeniji/development/apache.org/tomcat/MSAdventureWorksDWDB.Public

 

Clone Git Repository

Clone Git Repository

Syntax:

git clone git@github.com:<user-name>/<file>.git

 

Sample:


git clone git@github.com:DanielAdeniji/JavaJSPJSTLMSSQL.git

 

Output:

Here is the output we got back…




[dadeniji@adelia MSAdventureWorksDWDB.Public]$ ssh -vT git@github.com
OpenSSH_6.6, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.252.130] port 22.
debug1: Connection established.
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/dadeniji/.ssh/known_hosts:2

debug1: No more authentication methods to try.
Permission denied (publickey).
[dadeniji@adelia MSAdventureWorksDWDB.Public]$ 


 

 

Set up SSH Keys

We know that we have yet to set up SSH keys on this box.  And, unfortunately I do not recollect where I placed previously used ones.

So let us go re-create SSH (Private & Public) keys.

Thankfully, GitHub has very good documentation on doing so:
https://help.github.com/articles/generating-ssh-keys

SSH Key Folder Location

SSH Keys are kept in /home/<username>/.ssh and in our case it is /home/dadeniji/.ssh.

In Linux by convention folders whose name starts with . are hidden files.  And, so the folder might not show up.

Here is a default listing Folder Listing:

Folder-List-Visually

 

Enhanced Folder Listing:

On CentOS, to view hidden files, please click on the menu items “View”/ “Show Hidden Views” or use the keystrokes (CTRL-H).

Here is the “Show Hidden Views” picture:

Folder-List-Visually-after

 

 

Check for SSH Key

Command:


cd ~/.ssh
ls -al

Output:

 

ssh - list files

Generate SSH Key

Command:

ssh-keygen -t rsa -C "dadeniji@ephraimtech.com"

 

Output:

ssh-keygen

 

Add Key to SSH Agent

Command:

ssh-add ~/.ssh/id_rsa

 

Output:

ssh-add

 

Review SSH Keys

Let us re-issue ls, and see whether we now have our keys.

Command:

cd ~/.ssh
ls -al

Output:

ssh - list files (found)

Add SSH Keys to Git-Hub

  • Access Github
  • In the top bar (https://github.com)
  • topMenuClick on the wrench button    wrench  .
  • The “Account Settings” ( https://github.com/settings/profile ) will show up
  • The “Account Settings” screen looks like this:AccountSettings
  • Click on “SSH Keys”
  • SSH Keys:Listing for SSH Keys.SSHKeys
  • Click on the “Add SSH key”AddSSHKey
  • Post entering SSH KeyAddSSHKey [after]
  • Confirm password to continue — Enter passwordConfirmPasswordToContinue
  • Here is the the listing of our “SSH Keys”SSHKeys (After)
    We can see that the new key’s status is listed as  “Added just now — Never used“.

SSH Key – Test

Command:

ssh -T git@github.com

 

Output:

Output – Textual:


[dadeniji@adelia ~]$ ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
Hi DanielAdeniji! You've successfully authenticated, but GitHub does not provide shell access.
[dadeniji@adelia ~]$


Output – Image:

PermanentlyAddedTheRSAHostKeyForIPAddress

 

 

Clone Git Repository (Attempt #2)

Clone Git Repository

Syntax:

cd <home-directory>

git clone git@github.com:<user-name>/<file>.git

 

Sample:


cd /home/dadeniji/development/apache.org/tomcat/MSAdventureWorksDWDB.Public git clone git@github.com:DanielAdeniji/JavaJSPJSTLMSSQL.git

 

Output:

Here is the output we got back…

Textual:


Initialized empty Git repository in /home/dadeniji/development/apache.org/tomcat/MSAdventureWorksDWDB.Public/JavaJSPJSTLMSSQL/.git/
warning: You appear to have cloned an empty repository.


 

Image:

cloned-empty-git-repository

 

Git Repository – Add

Add Files

Syntax:

cd <home-directory>

git add <files>

 

Sample:


git add '*.jsp'

 

Output:

Textual:

fatal: Not a git repository (or any of the parent directories): .git

 

Image:

NotAGitRepository

 

Remediate

Googling on the error message tells me that I really needed to have indicated the folder that I wanted to use as my Git current folder.

As we did not indicate otherwise, a new folder is created underneath the current folder bearing:

inproper-use-of-git-clone

 

In the screen above the name of the folder is JavaJSPJSTLMSSQL.

 

Move Git Local Repository

Move Git Local Repository

Syntax:

cd <home-directory>

mv <local-folder>/.git . 

rm -rf <local-folder>

 

Sample:


cd /home/dadeniji/development/apache.org/tomcat/MSAdventureWorksDWDB.Public move JavaJSPJSTLMSSQL/.git . rm -rf JavaJSPJSTLMSSQL

 

Check Git Local Repository

 

Syntax:

git status --short

 

Sample:


git status --short

 

Output:

gitStatus--short

 

Reset Git Local Repository – Reset

 

Syntax:

git reset --hard

 

Sample:


git reset --hard

 

Output:

Textual:


fatal: Failed to resolve 'HEAD' as a valid ref.

 

Image:

failed to resolve head

 

We will ignore this error for now.

Git Repository – Add

Add Files

Syntax:

cd <home-directory>

git add <files>

 

Sample:


git add 'README.md'
git add '*.jsp'
git add '*.html'
git add 'META-INF/context.xml'
git add 'WEB-INF/*'

Git Repository – Create ignore file (.gitignore)

Add Files

Syntax:

touch .gitignore

 

Sample:

 

touch .gitignore

 

If there are files that we do not want shipped-off, we will list them in the .gitignore file.

Mask Private Data

We will like to share source code, but keep certain private data hidden.  We will use sed for that.

 

Sample:


sed --expression='s/HRPROD/dbHost/' --expression='s/username="hrdb"/username="dbUser"/' --expression='s/mygoodpwd/dbUserPassword/' META-INF/context.xml > META-INF/context.xml.tmp && mv META-INF/context.xml.tmp META-INF/context.xml sed --expression='s/HRPROD/dbHost/' --expression='s/hrdb;/dbUser;/' --expression='s/mygoodpwd/dbUserPassword/' jspSimple.jsp > jspSimple.jsp.tmp && mv jspSimple.jsp.tmp jspSimple.jsp

 

 

 

Git – Review File Status

Review Git Status in terms of what files are on.

Syntax:

git status

 

Sample:

git status

 

Output:

gitStatus

 

 

Git – Commit Changes – Locally

Commit Git Changes locally.

Syntax:

git commit -m <comment>

 

Sample:

git commit -a -m "initial batch"

 

Output:

gitCommit

 

Git – Commit Changes – Remotely

Commit Git Changes remotely.

Syntax:

git push -u origin master

Sample:

git push -u origin master

 

Output:

gitPush

 

Git – Review Github

Let us quickly review Github and make sure that our files are there.

Our URL is https://github.com/DanielAdeniji/JavaJSPJSTLMSSQL.

 

exploreFilesOnGithub

 

 

 

Git – Review Log

We use “git log” to review our change logs.

Syntax:

git log

Sample:

git log

Output:

gitLog

 

Listening to

Dave Loggins – Pieces of April
https://www.youtube.com/watch?v=gAlaYEmS0oY

 

 

References

References – Git – Tutorial

 

References – Git – SSH Key Management

 

References – Git – Q/A

 

References – Git – SSH Key – QA

 

 

References – SSH Key – Management

  • Git Tutorial starting with git using 10 commands

 

 

 

 

 

 

 

GitHub – Command Line – Processing

GitHub – Command Line – Processing

Once again returning to Mr. Hunt’s home work “Ghost Who Codes: How Anonymity is Killing Your Programming Career”.

I wanted to share a SQL Lab Experiment with others that can help me.  Currently, I have the Transact SQL code sprinkled in WordPress postings.  To consolidate those SQL bits in a few easy to access files, I have posted those files in a free, publicly available GitHub repository.

My current desktop is a Mac Laptop. And, thankfully there’s a Git Command Line toolset for the Mac OS X.

In an earlier posting, I documented the steps to install the Command Line Toolset on a Mac OSX (https://danieladeniji.wordpress.com/2013/04/26/technical-github-installation-on-mac-osx/).

So needed to share these files and post it to GitHub.

The Git Hub repository is https://github.com/DanielAdeniji/MSSQLTableSpoolPartitionIndexUnaligned

Here are the steps (to post files from my local desktop to the GitHub repository):

  • Start a Terminal Mode Session
  • Change Folder to Source code Folder (cd <source-code-folder>)
  • Create Git Repository (git init)
  • Add files to Git (git add)
  • Commit Changes locally (git commit)
  • Add Remote Repository (git remote add origin)
  • Replicate local changes to remote repository (git push origin master)

Processing

Start Terminal Mode

Change Folder

Syntax:

cd <folder>

Sample:

    cd /Users/dadeniji/Documents/TableSpool/PartitionIndexUnAligned

Create Git Repository

To prepare a folder for Git, issue the “git init” command
Syntax:

git init

Output:

Initialized empty Git repository in /Users/dadeniji/Documents/TableSpool/PartitionIndexUnAligned

Add Files

Add specific files (*.sql)
Syntax:

git add <file-name>

Output:


git add *.sql

git - add - sql

Add specific files (*.png)
Syntax:

    git add <file-name>

Output:

    git add *.png

git - add - png

Commit

Commit changes

To commit the changes locally issue the “git commit” command.

Syntax:

    git commit

Output:
— commit changes (editor opened prompting for a comment)

    git commit

Output:

    -- commit changes and attach a comment
    git commit -m "commit changes"

 

git - commit

Git – Remote Add origin

To bind our local folder to its corresponding GIT Folder, we need to get the URL to the specific repository.

Steps:

  • Launch Browser
  • Connect to your repository Tab
    https://github.com/<Username&gt;?tab=repositories (Syntax)
    https://github.com/DanielAdeniji?tab=repositories (Ours)
  • Select the corresponding repository
  • Click the repository link
  • The repository window appears
  • Access the “Code” Tab
  • Select the protocol you want; in our case SSH
  • Copy the URL; in our case for the MSSQLTableSpoolPartitionIndexUnaligned repository the URL will be git@github.com:DanielAdeniji/MSSQLTableSpoolPartitionIndexUnaligned.git

Git Hub – Repository

github - Repositories

URL – HTTP/SSH

github - repository - MSSSQLTableSpool - SSH

Syntax:

   git remote add origin 

Sample

   git remote add origin git@github.com:DanielAdeniji/MSSQLTableSpoolPartitionIndexUnaligned.git

Git – Review Remote repositories

Syntax:

  git remote -v show

Command:

   git remote -v show

Output:

git remote -v show
origin	git@github.com:DanielAdeniji/HadoopHBaseDemoMedia (fetch)
origin	git@github.com:DanielAdeniji/HadoopHBaseDemoMedia (push)

 

Git - Remote - Show 

 

Git – Post changes from machine to Remote repository (1st Attempt)

The “git push origin master” replicates the local repository to a remote repository.
Syntax:

  git push origin master

Command:

   git push origin master

Output:


To git@github.com:DanielAdeniji/MSSQLTableSpoolPartitionIndexUnaligned.git
 ! [rejected]        
master > master (non-fast-forward)
error: failed to push some refs to 'git@github.com:DanielAdeniji/MSSQLTableSpoolPartitionIndexUnaligned.git'
hint: Updates were rejected because the tip of your current branch is 
behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

git - push origin master {2013-04-27 10_36 PM}

Git – Pull latest code from Remote repository to local directory

The error message above:
Updates were rejected because the tip of your current branch is behind its remote counterpart. Merge the remote changes (e.g. ‘git pull’) before pushing again.
suggests that we need to pull the latest version from github’s repository.

To do so, we will issue a “git pull” command.

Syntax:

   git pull <specific-repository-url>;

Example:

  git pull git@github.com:DanielAdeniji/MSSQLTableSpoolPartitionIndexUnaligned.git

Here is the output:

Command:

Output:


From github.com:DanielAdeniji/MSSQLTableSpoolPartitionIndexUnaligned
* branch HEAD > FETCH_HEAD
Merge made by the 'recursive' strategy.
README.md | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 README.md

git - pull {2013-04-27 11-06 PM}

Git – Post changes from machine to Remote repository (works)

Syntax:

  git push origin master

Command:

   git push origin master

Output:

   git push origin master
   Counting objects: 13, done.
   Delta compression using up to 8 threads.
   Compressing objects: 100% (12/12), done.
   Writing objects: 100% (12/12), 53.89 KiB, done.
   Total 12 (delta 3), reused 0 (delta 0)
   To git@github.com:DanielAdeniji/MSSQLTableSpoolPartitionIndexUnaligned.git
   4489d9f..a727695  master > master

Screen Shot

git - push origin master {2013-04-27 11-20 PM}

References

GitHub Client Installation on Mac OSX

Introduction

Two months ago, to be exact on Feb 13th, 2013, I read Troy Hunt’s posting titled “The Ghost Who Codes: How Anonymity is Killing Your Programming Career” (http://java.dzone.com/articles/ghost-who-codes-how-anonymity).

Ever since I have being meaning to get a GitHub Account.  Today I finally did.

As I am cheap and I am mostly doing so as part of Mr. Hunt’s assigned home work, I went the path of a free, publicly available repository.  No Credit Cards, Nothing!

Here is a quick primer on how to install a GitHub Client on a Mac OS.

Tools – Command Line

The official tools are available @ http://git-scm.com/downloads.

The URL for the Mac OSX version is available @ http://git-scm.com/download/mac

Tools – GUI

A very good brochure of GitHub clients is available via http://git-scm.com/downloads/guis 

Tools URL Price
GitHub for MAC http://mac.github.com/ Free for personal Usage
Gitbox http://gitboxapp.com/ Free for personal Usage
GitX http://gitx.laullon.com/ Free for personal Usage
Atlassian – SourceTree http://www.sourcetreeapp.com/ Free for personal Usage
Collab.Net – GitEye http://www.collab.net/giteyeapp Free for personal Usage
Syntevo – SmartGit/Hg http://www.syntevo.com/smartgithg/index.html Free for personal Usage

Tools – Command Line – Install

  • Download the installer for your OS
  • In our case, our installer is http://git-scm.com/download/mac
  • Once the installer is downloaded, launch it
  • The first screen that will appear is the screen  pasted below and labelled “Git 1.8.2.1 Snow Leopard Universal”
  • On the screen labelled “Git 1.8.2.1 Snow Leopard Universal”, double-click on the “Git-1.8.2.1-Intel-universal-snow-leopard.pkg” icon
  • The first screen displayed is the Git Welcome Screen
  • The next screen is the “Standard Install on …”
  • The next screen is the “Install Confimation” Screen

Git – Installer – Extracted (1.8.2) – Installer

Git 1.8.2.1 -- Snow Leopard Intel Universal

Git Welcome Screen

GitHub - Welcome Screen

Confirm Install

Git - Install Confirm

Installation was successful

Git - Installation was succcessful

Tools – Command Line – Uninstall

The script for the Un-installer is pasted below.  The name of the file is uninstall.sh.

Here is what the uninstaller does:

  • Checks the default install folder (/usr/local/git)
  • If that folder is not present, the script terminates and returns 1
  • The user is prompted as to whether he/she wants to continue
  • Upon pressing yes, the following folders are removed /usr/local/git//etc/paths.d/git, and /etc/manpaths.d/git
  • The pkgutil utility is invoked

if [ ! -r "/usr/local/git" ]; then
  echo "Git doesn't appear to be installed via this installer.  Aborting"
  exit 1
fi
echo "This will uninstall git by removing /usr/local/git/**/*, /etc/paths.d/git, /etc/manpaths.d/git"
printf "Type 'yes' if you sure you wish to continue: "
read response
if [ "$response" == "yes" ]; then
  sudo rm -rf /usr/local/git/
  sudo rm /etc/paths.d/git
  sudo rm /etc/manpaths.d/git
  sudo pkgutil --forget --pkgs=GitOSX\.Installer\.git[A-Za-z0-9]*\.[a-z]*.pkg
  echo "Uninstalled"
else
  echo "Aborted"
  exit 1
fi

exit 0

Uninstaller steps are:

  • Right click on the downloaded file (git-xxx-intel-universal-snow-leopard.dmg)
  • From the drop-down menu, select DiskImageMounter
  • The screen shot below is shown
  • You want the uninstall.sh file; place that file somewhere you can get to  it (/tmp folder)
  • Launch Terminal
  • Issue “cd /tmp”


Git – Installer – Extracted (1.8.2) – Uninstaller

Git - Installer - Extracted (1.8.2)

Review Install

Post install, review install

Once the installation has complete, please take the following steps to review:

    • Launch a new terminal window (this ensures that your environment variable such as path have been updated)
    • Issue “git -version”

git --version

Git - Command -version

Book

Scott Chacon has a free book online.  The URL is http://git-scm.com/book.

References

References – pkgutil