Working with github

Although I have been using SVN for version control since 2006, still I got very little interaction with GitHub until very recently when I had to use it as a main requirement for a few projects. So, here is a little finding for those who are new to this service.

I assume you have already created an account depending on the package you got. Following commands are for linux (Ubuntu) server to install git and setup keys for secure communication.

sudo apt-get update

sudo apt-get install git

 

ssh-keygen -t rsa -b 4096 -C “EMAIL_ID”

eval $(ssh-agent -s)

ssh-add /SSH_PATH_ON_SERVER/.ssh/id_rsa

cat /SSH_PATH_ON_SERVER/.ssh/id_rsa.pub and copy it or install clip to use following command:

clip < /SSH_PATH_ON_SERVER/.ssh/id_rsa.pub

 

Better to create a repository without Readme file and add use following link to complete process:

 

  • Open Git Bash and browse to concerned directory
    git init
    git add .
    git commit -m "First commit while creating repository"
  • At the top of your GitHub repository’s Quick Setup page, click to copy the remote repository URL.
    git remote add origin Remote_Repository_URL
    git remote -v
     git push origin master

Following are the help documentation links:

https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/

https://git-scm.com/doc

 

Experiment with Hello World repository before working on actual projects. It will be helpful getting familiar to environment.

https://guides.github.com/activities/hello-world/

To clone a particular branch from git repository

git clone -b my-branch git@github.com:user/myproject.git

OR

git clone -b my-branch git@github.com:user/myproject.git target_empty_directory/

Update a directory from remote repository:

Traverse to target directory on your local system and execute:  git pull  This is equivalent to svn update

 

Trouble shooting with some error messages:

  • Following error means, we need to setup public/private key for the github+local computer to communicate properly (provided the remote user has access to repository)

$ git push origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

https://help.github.com/articles/checking-for-existing-ssh-keys/

https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

 

  • If its new repository and still you are getting following errors, Possibly you created repository with the readme file in it that needs to be synchronized.

$ git push origin master
To github.com:accountname/repository.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘git@github.com:accountname/repository.git’
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.

then:

$ git fetch  –all

$ git pull origin master –allow-unrelated-histories
From github.com:accountname/repository
* branch master -> FETCH_HEAD

 

 

 

One thought on “Working with github”

Leave a Reply

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