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)
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 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:
Experiment with Hello World repository before working on actual projects. It will be helpful getting familiar to environment.
To clone a particular branch from git repository
git clone -b my-branch email@example.com:user/myproject.git OR git clone -b my-branch firstname.lastname@example.org: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.
- 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
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘email@example.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.
$ git fetch –all
$ git pull origin master –allow-unrelated-histories
* branch master -> FETCH_HEAD