This post is about setting Git and GitHub. Let’s learn how to Git.
What is git ?
Git allows you, your friends, coworkers, a team of people to work together, all using same files. Oh. Aah. That’s a mess.
No not at all. Most operations in Git only need local files and resources to operate — generally no information is needed from another computer on your network. There are many ways it can be set up and configured.
What is GitHub?
Quoting the GitHub – guide :
GitHub provides desktop clients that include a graphical user interface for the most common repository actions and an automatically updating command line edition of Git for advanced scenarios.
How to Git and GitHub?
Install Git :
sudo apt-get install git sudo apt-get -y install git-core #Set User Info git config --global user.name Your Name git config --global user.email Your Email ID git config --global credential.helper 'cache --timeout=3600'
Now you are done with the basic stuff.
Let’s Create New Repository :
#Create a repo on GitHub, use the same name of the repo on your machine mkdir ~/Hello-World git init touch README git add README git commit -m 'first commit' git remote add origin http://github.com/Your-User-Name/Hello-World.git git push origin master
Using GitHub UI : Refer this.
You are done with your Hello World to Git and GitHub.
Now you can create new files (touch) -> add -> commit -> push them to the repository.
git remote add origin http://github.com/Your-User-Name/Hello-World.git git push origin master error: The requested URL returned error: 403 while accessing http://github.com/Your-User-Name/Hello-World.git/info/ref fatal: HTTP request failed
check what this gives you
git remote -v
origin http://github.com/Your-User-Name/Hello-World.git (fetch) origin http://github.com/Your-User-Name/Hello-World.git (push)
Everything is fine, the error is somewhere else, let’s look for it :
Try using SSH instead of HTTPs like,
git remote set-url origin ssh://github.com/Your-User-Name/Hello-World.git git push origin master
Check is it set?
git remote -v #You get origin ssh://firstname.lastname@example.org/Your-User-Name/Hello-World.git (fetch) origin ssh://email@example.com/Your-User-Name/Hello-World.git (push)
Did you get this?
The authenticity of host 'github.com (126.96.36.199)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,188.8.131.52' (RSA) to the list of known hosts. Permission denied (publickey). fatal: The remote end hung up unexpectedly
Try sshing your GitHub
ssh -T firstname.lastname@example.org #You get Permission denied (publickey).
Oh! let’s check are you connected to the correct server?
ssh -vT email@example.com</pre> <pre>OpenSSH_5.3p1 Debian-3ubuntu7.1, OpenSSL 0.9.8k 25 Mar 2009 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Connecting to github.com [184.108.40.206] port 22. debug1: Connection established. debug1: identity file /home/you/.ssh/identity type -1 debug1: identity file /home/you/.ssh/id_rsa type -1 debug1: identity file /home/you/.ssh/id_dsa type -1 debug1: Remote protocol version 2.0, remote software version libssh-0.6.0 debug1: no match: libssh-0.6.0
Try SSHing your GitHub :
ssh -T firstname.lastname@example.org #Always use the git user #You get Hi your-user-name! You've successfully authenticated, but GitHub does not provide shell access.
Let’s Push it!
git push origin master #Yayy! Counting objects: 3, done. Writing objects: 100% (3/3), 222 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To ssh://email@example.com/your-user-name/Hello-World.git * [new branch] master -> master
Generating ssh keys
cd ~/.ssh ls -al #You get total 12 drwx------ 2 you you 4096 2014-05-27 21:49 . drwxr-xr-x 83 you you 4096 2014-05-27 21:56 .. -rw-r--r-- 1 you you 2210 2014-05-27 21:58 known_hosts ssh-keygen -t rsa -C your_email #You get Generating public/private rsa key pair. Enter file in which to save the key (/home/you/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/you/.ssh/id_rsa. Your public key has been saved in /home/you/.ssh/id_rsa.pub. The key fingerprint is: de:22:21:8......... your_email The key's randomart image is: +--[ RSA 2048]----+ | | | . | | o o | | . B . . | ---------- --------- +-----------------+ #Add it ssh-add ~/.ssh/id_rsa Enter passphrase for /home/you/.ssh/id_rsa: Identity added: /home/you/.ssh/id_rsa (/home/you/.ssh/id_rsa) #Install xclip sudo apt-get install xclip xclip -sel clip < ~/.ssh/id_rsa.pub #Open your rsa public file gedit id_rsa.pub
Copy the contents of this file to GitHub, follow this to add it to your GitHub account.
#sshing your GitHub ssh -T firstname.lastname@example.org #and you are done Hi user-name! You've successfully authenticated, but GitHub does not provide shell access.
Refer this for more.
If you used the SSH procedure, you are using SSH port, if you didn’t then you are using HTTPs port.
Now ➡ and start the fun. 🙂