git and git hub for beginners


 A) git hub: 


2) sign up with email and create a username
3) create a new repository
  • suppose you have created a repository named 'Repo1'

 B) git initialization: 


2) download git application on your PC
3) install application
4) make a folder with any name on Desktop or anywhere in your PC
  • suppose you made a folder named 'MyProject' on Desktop
5) open git bash (this is command prompt for git)

6) write command: 
 cd Desktop/MyProject 
press Enter key
  • this will select the folder for git initialization
  • by this way you can select any folder you want, just write folder path after cd
7) write command:
 git init 
press Enter key
  • this will initialize git in that folder and you can see .git folder in your selected folder after this

 C) commit files to git 


  • after initialization, you need to add your email and username in git.
  • suppose you have used 'ramesh@gmail.com' as your email and 'ramesh101' as username on git hub while creating your account there.
  • to transfer files from git of your PC to git hub repository, you should add same email and username in git also.
1) write command in git bash:
 git config --global user.email ramesh@gmail.com 
press Enter key

2) write command:
 git config --global user.name ramesh101 
press Enter key
  • after this or before this suppose you have created a file named 'script1.js' in 'MyProject' folder of you PC.
  • you can check the status of this file in git
3) write command in git bash:
 git status 
press Enter key
  • you will see this message-
 Untracked files: 
     (use "git add <file>..." to include in what will be committed)
     script1.js 
  • it means the file you created is not tracked by git, so you need to make it track.
4) write command:
 git add script1.js 
press Enter key
  • to make git track more than 1 file at a time, use git add . command, by this command git tracks all the files that you have newly created or updated. 
  • you can use git add . for a single file also, remember, command is 'git add(space)(dot)'
5) write command: 
 git status 
press Enter key
  • you will see this message-
 Changes to be committed: 
   (use "git restore --staged <file>..." to unstage) 
         new file:   script1.js 
  • it means the file you created is tracked by git but not yet committed.
  • so you need to commit the file
6) write command:
 git commit -m "added file script1.js" 
  • here -m is to add message, you can add any message in double quotes after -m
press Enter key
  • you will see this kind of message-
 $ git commit -m "added script1.js" 
 [master 9d7271b] added script1.js 
  1 file changed, 0 insertions(+), 0 deletions(-) 
  create mode 100644 script1.js 

7) write command:
 git status 
press Enter key
  • you will see this kind of message- 
 On branch master 
 nothing to commit, working tree clean 
  • it means you have successfully committed file to git

 D) add files from git on your PC to remote repository of git hub 


  • first of all you have to link your git hub repository to git
  • visit git hub and login to it, open repository you created there already.
  • here I have already created repository named 'Repo1' on git hub.
1) copy the url of that repository
here that url is 'https://github.com/ramesh101/Repo1.git'

2) write command in git bash:
 git remote add origin https://github.com/ramesh101/Repo1.git 
press Enter key
  • now your git is linked with git hub
3) write command:
 git push -u origin master 
press Enter key
  • this will add the files from your git to git hub repository master branch i.e. here 'Repo1'
4) refresh git hub
you can see the files successfully added in 'Repo1' repository i.e. master branch


 E) create new branch in git, merge new branch & master branch, push new branch to git hub 


  • suppose you want to make a new branch named "Branch1"
1) write command in git bash:
 git branch Branch1 
press Enter key
  • you will not see any message, but by this way your branch is created
  • now you need to move/switch to Branch1 to work in that branch, for that use 'checkout' command
2) write command:
 git checkout Branch1 
press Enter key
you will see this message-

 Switched to branch 'Branch1' 
  • you can see all files from master branch in this new branch
  • now suppose have added/created a new file in Branch1 named 'script2.js' 
3) commit changes to git:
  • to commit this new file to git, follow the process that we have already learned above in 'C) commit files to git'
  • now, to push Branch1 to git hub you need to use push command
4) write command:
 git push -u origin Branch1 
press Enter key
  • by this way Branch1 is added to git hub
  • reload git hub, and you can see '2 branches' there 
  • now, in dropdown menu Branch1 is available to select
  • now, to add new files/changes from Branch1 to master branch, you need to merge Branch1 in master branch
  • to do this, first you need to move/switch to master branch, use 'checkout' command for this
  • after checkout in master, use 'merge' command
  • after merge, use 'push' command
5) write command:
 git checkout master 
press Enter key
you will see this message-

 Switched to branch 'master' 

6) write command:
 git merge Branch1
press Enter key
you will see this kind of message-

 Updating 9d7271b..5338508
 Fast-forward
  script2.js | 0
  1 file changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 script2.js
  • by this way, files/changes from Branch1 are added/updated in master branch of git on your PC
  • now to update this changes to master branch on git hub, you need to push it, use 'push' command for that
7) write command:
 git push -u origin master 
press Enter key
  • after this you can check status using 'status' command
8) write command:
 git status 
press Enter key
you will see this message-

 On branch master 
 Your branch is up to date with 'origin/master'. 

 nothing to commit, working tree clean 
it means you have successfully merged Branch1 to master branch & it is up to date!


 F) Delete local branch, Delete remote branch 


  • to delete a branch from git on your PC, you need to use '-d branch name' command
  • suppose you have to delete Branch1 from git on your PC
1) write command in git bash:
 git branch -d Branch1 
press Enter key
you will see this kind of message-

 Deleted branch Branch1 (was 5338508). 
  • now to delete Branch1 from remote repository i.e. git hub, you need to use 'push origin --delete branch name' command
2) write command:
 git push origin --delete Branch1 
press Enter key 
you will see this kind of message-

 To https://github.com/ramesh101/Repo1.git 
  - [deleted]         Branch1 

it means you have successfully deleted Branch1 form git hub
you can refresh git hub and see that there is no Branch1 available now!

    टिप्पण्या