GIT & GITHUB Tutorial

                                                 GIT & GIT HUB Tutorial 


Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Documentation and Downloads:


  1. GitHub for Windows.
  2. GitHub for Mac.
  3. For Linux and Solaris platforms, the latest release is available on Git Website.

Important Commands to practice on GIT:


Link

Process to push files from local directory to github repository. 

Generate SSH keys

1. Run command from git bash to generate ssh keys into local computer.
ssh-keygen -t rsa -b 4096 -C "bhardwaj@gmail.com"
2. run command eval $(ssh-agent -s) to generate pid.
3. ssh-add ~/.ssh/id_rsa to add ssh key to ssh id.
4. cat ~/.ssh/id_rsa.pub to check and copy key
5.  Go to github settings and add the copied key into new ssh key and name the key as well.
6.  Run command to add local directory to remote directory
  •  git remote add origin git@github.com:bhardwaj/globomantics_crm.git
7. Run command "git push -u origin master" it should push.

If it is not pushing as expect then switch to ssh

Run command for git bash shell
  • "git remote set-url origin git@*****(found after switching over to ssh"



Logs:
Logs during Practise

Check Git Status :

Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git status                                                                                                                                                                                                     
On branch master                                                                                                                                                                                                 
nothing to commit, working tree clean                                                                                                                                                                            
Initialize Git:
                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git init                                                                                                                                                                                                       
Reinitialized existing Git repository in C:/Users/Hitesh Kumar/Desktop/Devnet/sr                                                                                                                                 
c/git-intro/.git/                                                                                                                                                                                                
 
Check Git Status:                                                                                                                                                                                                               
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git status                                                                                                                                                                                                     
On branch master                                                                                                                                                                                                 
nothing to commit, working tree clean                                                                                                                                                                            
Create new file:                                                                                                                                                                                                                  
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ touch third.txt                                                                                                                                                                                                
Give read write permissions to file:
                                                                                                                                                                                                                
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ chmod 777 third.txt                                                                                                                                                                                            
Check git status: * Newly created file is untracked                                                                                                                                                                                                                  
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git status                                                                                                                                                                                                     
On branch master                                                                                                                                                                                                 
Untracked files:                                                                                                                                                                                                 
  (use "git add ..." to include in what will be committed)                                                                                                                                                 
                                                                                                                                                                                                                 
        third.txt                                                                                                                                                                                                
                                                                                                                                                                                                                 
nothing added to commit but untracked files present (use "git add" to track)                                                                                                                                     
Add newly created file to stage area*
                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git add third.txt                                                                                                                                                                                              
Checked Git Status again:
                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git status                                                                                                                                                                                                     
On branch master                                                                                                                                                                                                 
Changes to be committed:                                                                                                                                                                                         
  (use "git reset HEAD ..." to unstage)                                                                                                                                                                    
                                                                                                                                                                                                                 
        new file:   third.txt                                                                                                                                                                                    
                                                                                                                                                                                                                 
Commit Newly created file in master branch
                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git commit -m "I think it is good"                                                                                                                                                                             
[master 5903c86] I think it is good                                                                                                                                                                              
 1 file changed, 0 insertions(+), 0 deletions(-)                                                                                                                                                                 
 create mode 100644 third.txt                                                                                                                                                                                    
Checked Git status again:
                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git status                                                                                                                                                                                                     
On branch master                                                                                                                                                                                                 
nothing to commit, working tree clean                                                                                                                                                                            
Process to Push Files to Github

Generate /Create SSH Key:
                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ ssh-keygen -t rsa -b 4096 -C "bhardwaj@gmail.com"                                                                                                                                                       
Generating public/private rsa key pair.                                                                                                                                                                          
Enter file in which to save the key (/c/Users/Hitesh Kumar/.ssh/id_rsa):                                                                                                                                         
/c/Users/Hitesh Kumar/.ssh/id_rsa already exists.                                                                                                                                                                
Overwrite (y/n)? y                                                                                                                                                                                               
Enter passphrase (empty for no passphrase):                                                                                                                                                                      
Enter same passphrase again:                                                                                                                                                                                     
Your identification has been saved in /c/Users/Hitesh Kumar/.ssh/id_rsa.                                                                                                                                         
Your public key has been saved in /c/Users/Hitesh Kumar/.ssh/id_rsa.pub.                                                                                                                                         
The key fingerprint is:                                                                                                                                                                                          
SHA256:y58pxJ7rE6Fw9hnABGEAVxlp4mxgTlCYqtOXxf06DOQ bhardwajh@gmail.com                                                                                                                                     
The key's randomart image is:                                                                                                                                                                                    
+---[RSA 4096]----+                                                                                                                                                                                              
|+=+o*O.          |                                                                                                                                                                                              
|++..+ o          |                                                                                                                                                                                              
|=+ o . o         |                                                                                                                                                                                              
|..+ . * +        |                                                                                                                                                                                              
|.o   O +S=       |                                                                                                                                                                                              
|o . o E.*..      |                                                                                                                                                                                              
| . .   =o+       |                                                                                                                                                                                              
|        O. o     |                                                                                                                                                                                              
|       .o=+      |                                                                                                                                                                                              
+----[SHA256]-----+                                                                                                                                                                                              
                                                                                                                                                                                                                 
Check Process ID:
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ eval $(ssh-agent -s)                                                                                                                                                                                           
Agent pid 14868                                                                                                                                                                                                  
Add key to ssh agent:                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ ssh-add ~/.ssh/id_rsa                                                                                                                                                                                          
Identity added: /c/Users/Hitesh Kumar/.ssh/id_rsa (bhardwaj@gmail.com)                                                                                                                                    
         
Open ssh public key file to copy key to Github settings:
                                                                                                                                                                                                       
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ cat ~/.ssh/id_rsa.pub                                                                                                                                                                                          
ssh-rsa 8888888888888888888**************************

                      
MQ== bhardwaj@gmail.com                                                                                                                                                                                   
Run command to Push Git                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git push -u origin master                                                                                                                                                                                      
fatal: 'origin' does not appear to be a git repository                                                                                                                                                           
fatal: Could not read from remote repository.                                                                                                                                                                    
                                                                                                                                                                                                                 
Please make sure you have the correct access rights                                                                                                                                                              
and the repository exists.                                                                                                                                                                                       
Add repos to remote directory:
                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git remote add origin git@github.com:bhardwaj/globomantics_crm.git                                                                                                                                      
Again push local repo to remote repos:
                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git push -u origin master                                                                                                                                                                                      
Enumerating objects: 14, done.                                                                                                                                                                                   
Counting objects: 100% (14/14), done.                                                                                                                                                                            
Delta compression using up to 8 threads                                                                                                                                                                          
Compressing objects: 100% (9/9), done.                                                                                                                                                                           
Writing objects: 100% (14/14), 1.31 KiB | 111.00 KiB/s, done.                                                                                                                                                    
Total 14 (delta 1), reused 0 (delta 0)                                                                                                                                                                           
remote: Resolving deltas: 100% (1/1), done.                                                                                                                                                                      
To github.com:bhardwaj/globomantics_crm.git                                                                                                                                                               
 * [new branch]      master -> master                                                                                                                                                                            
Branch 'master' set up to track remote branch 'master' from 'origin'.                                                                                                                                            
                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$            
                                                                                                                                                                                                    

Process to create a new Branch in Git

Create new branch
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git branch devbranch                                                                                                                                                                                           
Check out into respective branch                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (master)                                                                                                                                              
$ git checkout devbranch                                                                                                                                                                                         
Switched to branch 'devbranch'                                                                                                                                                                                   
Push origin to Github

                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (devbranch)                                                                                                                                           
$ git push -u origin devbranch                                                                                                                                                                                   
Total 0 (delta 0), reused 0 (delta 0)                                                                                                                                                                            
remote:                                                                                                                                                                                                          
remote: Create a pull request for 'devbranch' on GitHub by visiting:                                                                                                                                             
remote:     
https://github.com/bhardwajhitesh9/globomantics_crm/pull/new/devbranch                                                                                                                              
remote:                                                                                                                                                                                                          
To github.com:bhardwaj/globomantics_crm.git                                                                                                                                                               
 * [new branch]      devbranch -> devbranch                                                                                                                                                                      
Branch 'devbranch' set up to track remote branch 'devbranch' from 'origin'.                                                                                                                                      
                                                                                                                                                                                                                 
Hitesh Kumar@hitesh MINGW64 ~/Desktop/Devnet/src/git-intro (devbranch)                                                                                                                                           
$        
  

Comments