Download - Git workshop
Git Workshop
What is Git ?
● Git is VCS , SCMGit is VCS , SCM
● Alternatives : Bazaar, Subversion and Alternatives : Bazaar, Subversion and Mercurial ...Mercurial ...
What can Git do ?
● Tracking code changes.Tracking code changes.
● Branching.Branching.
● MergingMerging code.code.
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.
Git Architecture
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.
Setting up Git ..
Setting up Git ..
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
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
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
Setting up the first repo
● Create a new empty repo.Create a new empty repo.
● IssuesIssues
● WikiWiki
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
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
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
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
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
Cloning | Cloning
➔ git clone git clone <repo url><repo url> : Clones a repo : Clones a repo
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>
Github social features
● ForkingForking
● Pull requestsPull requests
Git Support
● https://www.facebook.com/groups/gitsupport/https://www.facebook.com/groups/gitsupport/
Get Git flavored IDEs
● Visual StudioVisual Studio
– Git ExtensionGit Extension● EclipseEclipse
– EGitEGit● Source TreeSource Tree
● SmartGitSmartGit