Skip to content
Muhammad Ali Mughal edited this page May 6, 2016 · 1 revision

#GIT TUTORIAL

##Practise session # 1--

Steps required to install git--

1, Go to http://git-scm.com (Install git from here for windows / linus or Mac)--

2, Run setup--

3, Must check-in Windows Installer Integration (if it is not already check-in)--

4, click Next--

5, Finish--

Once you are done with installation goto cmd(command prompt) and write git--

(installation will be confirmed)--

Then follow these steps:--

1, Make an empty folder named as (Git-Practise) or as per your choice anywhere in your system--

2, Right click to the folder--

3, Click "Git Bash Here"--

4, write git init--

5, Enter--

Your's empty folder will act as repository now--

.--

.--

.--

##Practise session # 2--

1, make an empty folder anywhere in your system (use name of your choice)--

2,open cmd(command prompt) with the extension of that folder or gitbash --

3, make that folder as repository using command (your working directory will now act as git repository)--

4, with in the folder make two or more text files --

5, goto cmd/gitbash and write git status --

Note:- (you will find 2 untrack files in red)--

6, when you are done with changes write <git add -A> , <git add .> or <git add "FILE NAME"> as this will add your files to stage--

Note:- difference b/w above mention 3 commands--

...i, <git add -A> :- this will add all files from root , children , siblings to stage--

...ii, <git add .> :- this will add files from the folder where you are standing to stage--

...iii, :- this will add only specific file whose name you have written in command to stage--

7, making your file from unstage to stage means that your file is ready to store in repository and we call this term as "commit" so to commit we use commands <git commit -m "write msg here"> or --

Note:- commit will store all files from stage level to repository --

difference b/w above mention 2 commands--

...i, <git commit -m "" :- this command will store single line message while commiting--

...ii, :- this command is use to store multiple line base message using following steps--

.........*, write command --

.........*, press i (insert)--

.........*, write your multiple line base message (you may use enter too)--

.........*, (to exit):- press esc and then write :wq (write and quit) and enter--

8, goto any file inside the folder and write "hello world" inside it and then goto cmd/gitbash and write ... you will see modified written along with your file name in which you have done changes in red in unstage mode ... now again you will have to add it using git add command (mention above) and then again commit it using git commit command (mention above)--

.--

.--

.--

##Practice session # 3--

.--

--> Continuity of Practice session # 2--

.--

1, To unstage any stage/commit files we have following 2 ways--

.......i) $git reset HEAD (this will unstage files from stage level)--

.......ii) $git rm --cached (this will unstage from stage and commit level)--

2, To shift back to the previous commit from existing commit we use :---

........ $git reset --hard HEAD--

3, To check value of an object which includes user name and user email we use :---

.......i) $git config user.name--

.......ii) $git config user.email--

4, To ignore any file to not to include in your repository we use the following steps:---

  • make a .gitignore file from git bash by using command :- $touch .gitignore--

  • write git status in terminal , you will see .gitignore in untracked mode--

  • write $git add .gitignore or $git add . to make it stage--

  • write $git commit -m "git will ignore this" to commit it--

.........After doing all above mention steps you can go to working directory and open .gitignore file and write there inside for example : Folder1--

.........Make a new folder in your repository named as Folder1 --

.........Goto gitbash and write git status, you will find nothing as git has ignored Folder1--

Note: You can ignore any file , folder etc , all you have to write is file name with proper extension or use . it will ignore all , where (*) represent name of file and extension and for folder u will have to write only folder name.--

5, To highlight any commit as important apply tag to it by using --

.........i) $ git tag –a –m "This is my first tag"--

(Note: tag will apply to your last commit so apply above mention command after commit)--

Note:- Practice above mention steps--

...........&--

...........see next post (4) for branch base details --

.--

.--

.--

##Practice session # 4--

.--

###"BRANCH"--

.--

A branch is essentially another way your repository takes. While programming, you will use branches to experiment with changes, without breaking the working code.--

You will use them to keep track of some extensive work, such as the development of a new feature, to maintain different versions or releases of your project. To put it simply, you will use it always.--

By default you have branch master initially in which you start working in repository. However, you can make another branch to work on that can be merge with your master branch.--

.--

1,Use $git branch in git bash to check in which branch you are standing ........ Within master branch make 2 files in directory with add and commit--

2, Use $git branch to make new branch--

3, Use $git checkout to switch to new branch--

....You can also use $git checkout - to switch to previous branch--

.........Here you will see 2 files of master branch , now make 1 more file in this new branch with add and commit--

4, Now again switch to master branch by writing $git checkout master--

Note: You will find still 2 file again in your working directory instead of total 4 as you made 2 files in new branch also that donot exist in master branch but it can be merge through $git merge --

.--

.--

Best of luck 👍

Clone this wiki locally