22
Git Workshop

Git workshop

Embed Size (px)

Citation preview

Page 1: Git workshop

Git Workshop

Page 2: Git workshop

What is Git ?

● Git is VCS , SCMGit is VCS , SCM

● Alternatives : Bazaar, Subversion and Alternatives : Bazaar, Subversion and Mercurial ...Mercurial ...

Page 3: Git workshop

What can Git do ?

● Tracking code changes.Tracking code changes.

● Branching.Branching.

● MergingMerging code.code.

Page 4: Git workshop

How does it work ?

● Tracking changes in text files.Tracking changes in text files.

● Committing changes.Committing changes.

● Working directory , Staging areaWorking directory , Staging areaand the remote repository.and the remote repository.

● .git folder..git folder.

Page 5: Git workshop

Git Architecture

Page 6: Git workshop

Getting Started ..

● Installing and configuring git.Installing and configuring git.

– http://git-scm.com/http://git-scm.com/● Git, Github and bitbucket.Git, Github and bitbucket.

● Creating Creating GitHubGitHub account. account.

Page 7: Git workshop

Setting up Git ..

Page 8: Git workshop

Setting up Git ..

Page 9: Git workshop

Setting up Git ..

● Adding Ssh key :Adding Ssh key :

– Go to %user_profile%/.ssh/id_rsa.pubGo to %user_profile%/.ssh/id_rsa.pub

– Open Open https://github.com/settings/profilehttps://github.com/settings/profile→ SSH keys→ SSH keys

– Choose to add a keyChoose to add a key

– You'll receive a notifying emailYou'll receive a notifying email

Page 10: Git workshop

Setting up Git ..

● NO MORE PASSPHRASES !!!NO MORE PASSPHRASES !!!

notepad.exe ~/.bashrcnotepad.exe ~/.bashrc

edit with :edit with :#! /bin/bash #! /bin/bash eval `ssh-agent -s` eval `ssh-agent -s` ssh-addssh-add

save and closesave and close

Page 11: Git workshop

WarmUp with Linux Commands

Open Git bash and try :Open Git bash and try :➔ pwd : Displays present working directorypwd : Displays present working directory➔ ls -ah : Displays all files in the directoryls -ah : Displays all files in the directory➔ cd : Changes the current directorycd : Changes the current directory➔ mv : Moves file or directorymv : Moves file or directory➔ rm : Removes file or -R for directoryrm : Removes file or -R for directory➔ cp : Copies file or directorycp : Copies file or directory➔ touch : Creates an empty filetouch : Creates an empty file

Page 12: Git workshop

Setting up the first repo

● Create a new empty repo.Create a new empty repo.

● IssuesIssues

● WikiWiki

Page 13: Git workshop

Getting our hands dirty

➔ git statusgit status : Shows the current git repo status : Shows the current git repo status

Shows that it's not a git repoShows that it's not a git repo

➔ git initgit init : Initializing git repo : Initializing git repo

Adds .git folder for repo settingsAdds .git folder for repo settings

➔ git remote add origin git remote add origin <repourl><repourl> : Adds remote to the : Adds remote to the repositoryrepositoryOrigin is an optional name points to the remote repoOrigin is an optional name points to the remote repo

Page 14: Git workshop

Your first commit

➔ touch readmetouch readme : Creates a new readme file : Creates a new readme file

➔ notepad.exe readmenotepad.exe readme : To edit .. optional : To edit .. optional

➔ git statusgit status : Shows the current git repo status : Shows the current git repo status

➔ git addgit add : Adds files to track or submit changes to : Adds files to track or submit changes to commitcommit

None tracked files won't be committed for changesNone tracked files won't be committed for changes

Page 15: Git workshop

Your first commit

➔ git commit -m 'Commit Message'git commit -m 'Commit Message' : Commits changes : Commits changes in added filesin added filesOptional commit message after -m , -a for committing Optional commit message after -m , -a for committing and adding all filesand adding all files

➔ git rm git rm <filename><filename> : Delete a file : Delete a fileDon't forget to add deleted files when deleted Don't forget to add deleted files when deleted manually without “git rm” commandmanually without “git rm” command

Page 16: Git workshop

Pushing and fetching

➔ git push origin mastergit push origin master : Pushes commits to origin : Pushes commits to origin remoteremote

➔ git fetch origingit fetch origin : Checks the latest changes in origin : Checks the latest changes in origin

➔ git merge origin/mastergit merge origin/master : Merges origin/master with : Merges origin/master with local current branchlocal current branch

Page 17: Git workshop

Branching

➔ git branchgit branch : Show branches and current branch : Show branches and current branch

➔ git checkout -b git checkout -b <branch><branch> : Create and checkout the : Create and checkout the new branchnew branch

➔ git branch -d git branch -d <branch><branch> : Delete specified branch : Delete specified branch

Page 18: Git workshop

Cloning | Cloning

➔ git clone git clone <repo url><repo url> : Clones a repo : Clones a repo

Page 19: Git workshop

Conflicts !

● When merging modified file from remote with modified file When merging modified file from remote with modified file in local repo conflicts encounteredin local repo conflicts encountered

● Conflicts are in the conflicted files with headers and Conflicts are in the conflicted files with headers and footers :footers :

<<<<<<< HEAD<<<<<<< HEADlocal versionlocal version==============merged versionmerged version>>>>>>> >>>>>>> <branch><branch>

Page 20: Git workshop

Github social features

● ForkingForking

● Pull requestsPull requests

Page 21: Git workshop

Git Support

● https://www.facebook.com/groups/gitsupport/https://www.facebook.com/groups/gitsupport/

Page 22: Git workshop

Get Git flavored IDEs

● Visual StudioVisual Studio

– Git ExtensionGit Extension● EclipseEclipse

– EGitEGit● Source TreeSource Tree

● SmartGitSmartGit