Bsadd training-git
-
Upload
maksud-chowdhury -
Category
Education
-
view
144 -
download
0
Transcript of Bsadd training-git
![Page 1: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/1.jpg)
A Distributed Version Controlling System
BUET Systems Analysis, Design & Development Group
Md. Maksud Alam ChowdhuryCSE ,[email protected]
![Page 2: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/2.jpg)
![Page 3: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/3.jpg)
A version controlling system
Distributed
Most popular software for managing codebases
Support for remote collaboration
![Page 4: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/4.jpg)
![Page 5: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/5.jpg)
Remove millions of backup folder
Smartly merge separate codes
Track day to day changes of codes
Small changes won’t destroy whole project
Disk crash or virus won’t hamper your codes ever !!!!!!!!!!!!!
![Page 6: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/6.jpg)
![Page 7: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/7.jpg)
![Page 8: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/8.jpg)
![Page 9: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/9.jpg)
Branching & Merging (to be discussed widely)
Small & Fast
Distributed
Free & Open Source
![Page 10: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/10.jpg)
![Page 11: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/11.jpg)
Standalone version:http://git-scm.com/downloads
Portable version:https://code.google.com/p/msysgit/downloads/list
They both have command line interface .
![Page 12: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/12.jpg)
![Page 13: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/13.jpg)
Navigate to your project folder
Right Click on Folder-> Git Bash
It will open a shell
![Page 14: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/14.jpg)
![Page 15: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/15.jpg)
Type git init to initialize a git repo on your project folder.
Having existing codes won’t cause problem
In most cases , you will create a repo where you have your codes.
Note that we are in master branch by default
We will discuss it later on branching.
![Page 16: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/16.jpg)
![Page 17: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/17.jpg)
Let’s add some files (not needed in case already have existing codes)
Let’s create “a.cpp” , “b.txt” , “c.cpp” in the “DemoApp” Folder.
Add some dummy texts on them
Current Working DirectoryDemoApp/
|--a.cpp|--b.txt|--c.cpp
![Page 18: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/18.jpg)
![Page 19: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/19.jpg)
So we think our app is stable right now.
So we need to commit the files to be preserved
Type git add .
Type git commit –am “message describing commit”
So git will have save current codes as the latest stable code on master branch
![Page 20: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/20.jpg)
![Page 21: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/21.jpg)
We can check the status of the current condition of codes by typing
git status
Every commit is saved uniquely with a number
You can switch back to any previous commit any time
![Page 22: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/22.jpg)
![Page 23: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/23.jpg)
![Page 24: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/24.jpg)
By Default we are in the master branch which is root .
Branches are independent of each other
Enough talking !!!!!!
Let’s create another branch “dev” which is a development version.
We will experiment in the dev branch where as fully stable codes will be in master branch
![Page 25: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/25.jpg)
Typegit checkout –b dev
It will create a new branch dev and switch to “dev“ branch
The new branch will contain exact copy from where we created it.
Any change we do now in the working directory , after commit will go for “dev” branch
![Page 26: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/26.jpg)
![Page 27: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/27.jpg)
Let’s change the content of “b.txt” and create “d.txt”
So we have changed “b.txt” and added “d.txt”
Now Type git status
![Page 28: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/28.jpg)
![Page 29: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/29.jpg)
We now commit the current working directory
So Type Again
git add .
git commit –am “commit message”
![Page 30: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/30.jpg)
![Page 31: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/31.jpg)
Let’s switch back to the “master” branch
Type git checkout master
It will restore the master branch codes
Note that “b.txt” is restored & d.txt is gone
So you have two separate version of codes
![Page 32: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/32.jpg)
On Master Branch On dev branch
![Page 33: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/33.jpg)
![Page 34: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/34.jpg)
So we were in the master branch again
We are sure to merge the dev branch into master branch
Type git merge dev
![Page 35: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/35.jpg)
![Page 36: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/36.jpg)
Surprisingly there is no conflict in “b.txt”
Because until now you are the only person who changed the branch in local workstation
![Page 37: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/37.jpg)
![Page 38: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/38.jpg)
We need a central place to synchronize the team members repositories
Github , Bitbucket , gitorious , Assembla , repositoryhosting etc.
Github only provides public repo
If you don’t want it to be public go for Bitbucket
https://bitbucket.org/account/signup/
![Page 39: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/39.jpg)
![Page 40: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/40.jpg)
![Page 41: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/41.jpg)
![Page 42: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/42.jpg)
![Page 43: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/43.jpg)
![Page 44: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/44.jpg)
Similarly as previous slide
Type
git push origin dev
![Page 45: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/45.jpg)
![Page 46: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/46.jpg)
![Page 47: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/47.jpg)
There are several mechanisms [try googling]
We will show an easy approach for small teams
We will maintain master for ultimate stable version .
Each team member will have their own branch
![Page 48: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/48.jpg)
After finalizing some features team members will create a temporary branch
The temporary branch will be incrementally merged and tested by team captain
But there might be conflict in configuration files which might hamper project.
[Android menifest.xml , database settings etc ]
![Page 49: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/49.jpg)
Do ignore such files while committing
Create a .gitignore file and list the directories or file not to be tracked
Keep a list of changelog.txt file
After merging master do manually change the configurations
![Page 50: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/50.jpg)
Conflicts arise when You have changed your local files and committed them in your branch
But someone else have also changed the same files in his own branch
You want to merge his branch
Git will have no way to decide which one to keep and which one to abandon
So it keeps both of them in a way you can identify difference.
![Page 51: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/51.jpg)
We change our local file b.txt again in master
Add , Commit it
We pull some previous version of the same file in dev
git pull origin dev
Pull = fetch + merge
Now this will create a conflict
![Page 52: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/52.jpg)
![Page 53: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/53.jpg)
![Page 54: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/54.jpg)
Here head is local version
Lower part is the fetched version
The marker is where things actually started to be different
It would not create a conflict if appending was required or creating a new or deleting a file was required
But here a complete rewrite is required
![Page 55: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/55.jpg)
Git tool command
Manually change the conflicting files
Add, Commit , Push
Don’t Pull directly
At first fetch (git fetch origin dev)
See Whether any difference (git diff origin/dev)
The decide to merge
![Page 56: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/56.jpg)
If you already have a repo on bitbucket or github like the one we created
Just type
git clone <http_link_of_project>
So you don’t need to bother about backup or disk lost
![Page 57: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/57.jpg)
![Page 58: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/58.jpg)
![Page 59: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/59.jpg)
git init git add . git commit –am “<your commit message>”
git status
git checkout –b <New_Branch_Name> git checkout <Branch_Name> git merge <Branch_Name>
git remote add <Name_For_Server> <Link_Of_Your_Project>
git push <Name_For_Server> <Branch_To_Push>
git pull <Name_For_Server> <Branch_To_Pull>
git fetch <Name_For_Server> <Branch_To_Fetch>
git diff <Branch_To_Compare_With_Current_Branch>
![Page 60: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/60.jpg)
![Page 61: Bsadd training-git](https://reader030.fdocuments.us/reader030/viewer/2022032504/55c34fcebb61eb75778b47a9/html5/thumbnails/61.jpg)
http://git-scm.com/
http://gitref.org
https://bitbucket.org