Git BasicsMd. Emran Ul HadiSoftware Engineer WNeeds Ltd
What well cover• Concept of Version control system• Concept of Git• Some basic commands
Version controlMost used Concurrent version system(CVS) andSubversion(SVN).Key concepts: • Central source control system • users check code into server • requires connection to the server to perform commits, updates etc.
Git ???????• Distributed Version Control System• Like sub-version but better...• Created by Linus Torvald
WHY Git?????? Distributed repository • Self contained • Full history of commit • You can commit/branch/merge locally • Read fast and offline • No "latest revision": revision unique ID
Git Started getting started • move to a directory with code you’d like to manage with git: # git init • you’ve now created your ﬁrst git repository! For remote repository access: # git clone remote_git_repository_url Example: # git clone email@example.com:mobbazaar/api
Useful basics commands git init ‣ repository setup git add ‣ add ﬁles to queue for next commit git commit ‣ commit queued ﬁles git push ‣ push commit(s) to remote repository git pull ‣ fetch changes from remote repository git clone ‣ clone repository into a local directory .gitignore ‣ ignore speciﬁc ﬁles by adding them here
Continue...git status ‣ Show uncommited changesgit rm ‣ Remove a file from a repositorygit mv ‣ Move a file within repositorygit diff ‣ Generate a differences between multiple commitsgit log ‣ View a log of commits
Branchinggit branch new_branch create new branchgit branch -b feature2 create new branch and switch to that branchgit commit save some workgit checkout master switch backgit merge feature2 work is merged ingit rebase feature2 work played on topgit branch -d feature2 delete branch
tagging and merginggit merge branch_name Merge changes from branch_name to the current branchgit tag -a name Add a tag with a indicated namegit tag -l List tagsgit push --tags Push tags to remote repository
Handling Some critical situation • Changing your last commit # git commit --amend • Unstaging a staged File # git reset HEAD FILE_NAME • Unmodifying a modified File # git checkout -- FILE_NAME
Some rules have to follow• NEVER pull when you have uncommitted changes - commit your work ﬁrst.• First PULL then PUSH• If working on a feature, use a local branch, then this leaves the master open for other ﬁxes.