19
Git Workshop by Kugathasan Abimaran

Git workshop - University of Moratuwa, Department of Computer Science and Engineering

  • Upload
    wso2

  • View
    76

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Git workshop - University of Moratuwa, Department of Computer Science and Engineering

Git Workshopby Kugathasan Abimaran

Page 2: Git workshop - University of Moratuwa, Department of Computer Science and Engineering

Getting Git

Page 3: Git workshop - University of Moratuwa, Department of Computer Science and Engineering

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

GUI/References

• Gitk – for Linux• Git Extentions – For Windows

• Home Page : http://www.git-scm.com/• Reference : http://gitref.org/

Page 19: Git workshop - University of Moratuwa, Department of Computer Science and Engineering

For more informationGeneralCareersWeb

: [email protected]: [email protected]: www.hSenidMobile.com