Git workshop - University of Moratuwa, Department of Computer Science and Engineering
Transcript of Git workshop - University of Moratuwa, Department of Computer Science and Engineering
![Page 1: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/1.jpg)
Git Workshopby Kugathasan Abimaran
![Page 2: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/2.jpg)
Getting Git
![Page 3: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/3.jpg)
Why Version Control?
• Made a change to code, realized it was a mistake and wanted to go back?
• You don't lose anything. • I never again commented out code, I simply delete it• Working as a Team..?• Wanted to experiment new feature without affecting working
code?• What did I do yesterday?• Wanted Copy of Copy of Copy of Project?
![Page 4: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/4.jpg)
Git
• A directory content management system• Download & Install– http://msysgit.github.com/
• git help• git <command> -h• $HOME/.gitconfig
– git config --global user.name “Kugathasan Abimaran"– git config --global user.email [email protected]– git config --global color.ui true
![Page 5: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/5.jpg)
GitHub
• Build Software Better and Together.• Create a GitHub account• Install GitHub for Windows from here– http://github-windows.s3.amazonaws.com/GitHu
bSetup.exe• World largest open source community• Create own repository • Work on your dream project..?
![Page 6: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/6.jpg)
Create/Clone
• Create a git repository– git init
• Obtains a copy of a project for you with entire history
• Valid URLs are project directory names by various protocols – git clone [email protected]:abi-maran/demo.git– git clone https://github.com/abi-maran/demo.git
• Clone the repository from https://github.com/abi-maran/demo
![Page 7: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/7.jpg)
Commit
• Git uses two-step process to get changes into the repository.– Staging changes adds it to index or staging area.– Commit
![Page 8: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/8.jpg)
Commit …
• Each commit needs a commit message.• Git don’t track empty directories• git status
![Page 9: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/9.jpg)
Fix/Revert Commit
• Change last commit– git commit –amend
• Unmodify modified file– git checkout -- file.py
• Git revert <commit-id>• By creating new commit that reverse the
commit
![Page 10: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/10.jpg)
Differences
• git diff – changes between index and working files
• git diff HEAD • git diff --stat• git diff $commit $commit• git log
![Page 11: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/11.jpg)
Pull/Push to Repo
• git pull <remote> <rbranch>• git push <remote> <rbranch>
![Page 12: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/12.jpg)
Ignoring Files
• For the which you don’t want to add in git repo forever!
• .gitignore file – a project specific file• .git/info/excludes – global
![Page 13: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/13.jpg)
Stashing
• To save uncommitted files and return clean repo – git stash “description”– Do that work– git stash apply
![Page 14: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/14.jpg)
Branch
• Master is the default branch• git branch –l / -r / -a• Create a branch– git branch name
• git checkout branch
![Page 15: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/15.jpg)
Merge Branches
• To share changes between branches• Fast-forward merge• Recursively merge• Cherry-pick
![Page 16: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/16.jpg)
Conflicts
• When both changes the same line of code<<<<<<< HEADdef _handle_response(self, response, data=[], raw=False):return data if raw else simplejson.loads(data)=======def _handle_response(self, response, raw=False, data=[]):if raw:return datareturn simplejson.loads(data)>>>>>>> added_raw
git merge tool
![Page 17: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/17.jpg)
Tag
• To mark milestones in your project such as releases.
• Read only
![Page 18: Git workshop - University of Moratuwa, Department of Computer Science and Engineering](https://reader033.fdocuments.net/reader033/viewer/2022042701/55c4be48bb61ebc7118b458a/html5/thumbnails/18.jpg)
GUI/References
• Gitk – for Linux• Git Extentions – For Windows
• Home Page : http://www.git-scm.com/• Reference : http://gitref.org/