Git Basic Concepts and Usage

Git Basic Concepts and Usage

git Basic concepts and usage Francis Colas What is git? git concepts Standard commands Feature branch workflow Conclusion 2 – Francis Colas – git basics 01 What is git? What is git? Revision control Source code: I everything is source code, I usually written in an iterative process, I sometimes by several persons; Revision control: I management of versions of documents, I tracking of changes, I restoration of previous state, I similar concepts to a database; Some generic concepts: I atomicity: ensuring consistency of state, I distributed/centralized: communication model of changes, I branches and tags: development direction and milestones, I locking/merging: handling of concurrent changes. 4 – Francis Colas – git basics What is git? History of git Timeline: before hand-numbered or date-stamped copies, 1990 CVS: centralized and non atomic, 2000 Subversion: centralized and atomic, 2000s GNU Arch, Monotone, Darcs: decentralized and atomic, 2005 Linux cannot use BitKeeper anymore, 2005 answer: mercurial and git. 5 – Francis Colas – git basics 02 git concepts git concepts General characteristics Repositories: I monolithic and self-sufficient, I everybody has a full clone, I in particular: no need for a connexion to commit. Concepts: I git handles files (no empty directory), I central objects are commits: I set of file changes,1 I applied on top of a given [list of] commit[s], I tags and branches just point to a commit, I remotes are pointers to other clones (github, gitlab, other clone somewhere...). 1actually, they are more a snapshot of the state 7 – Francis Colas – git basics git concepts Staging area Three (conceptual) places: I working directory: the files in the filesystem, I staging area: the files as how they’ll be committed, I git repository: committed files. What it means: I changes happen in working directory, I need for preparation of the commit using the staging area, I actual commit is a frozen snapshot of the staging area. 8 – Francis Colas – git basics 03 Standard commands Manipulating the staging area: I git add <files>: add current state of files to next commit, I git rm <files>: delete files, I git mv <oldname> <newname>: move/rename a file. Looking at status: I git status: list state of working copy with respect to last commit. Commit and transmission: I git commit -m "commit message": record changes into a commit, I git pull [<url|remote>]: get changes and merge them, I git push [<url|remote>]: sends commit to remote/url. Standard commands Basic commands Initialization: I git init <name>: initialize an empty repository , I git clone <url>: clone a repository, 10 – Francis Colas – git basics Looking at status: I git status: list state of working copy with respect to last commit. Commit and transmission: I git commit -m "commit message": record changes into a commit, I git pull [<url|remote>]: get changes and merge them, I git push [<url|remote>]: sends commit to remote/url. Standard commands Basic commands Initialization: I git init <name>: initialize an empty repository , I git clone <url>: clone a repository, Manipulating the staging area: I git add <files>: add current state of files to next commit, I git rm <files>: delete files, I git mv <oldname> <newname>: move/rename a file. 10 – Francis Colas – git basics Commit and transmission: I git commit -m "commit message": record changes into a commit, I git pull [<url|remote>]: get changes and merge them, I git push [<url|remote>]: sends commit to remote/url. Standard commands Basic commands Initialization: I git init <name>: initialize an empty repository , I git clone <url>: clone a repository, Manipulating the staging area: I git add <files>: add current state of files to next commit, I git rm <files>: delete files, I git mv <oldname> <newname>: move/rename a file. Looking at status: I git status: list state of working copy with respect to last commit. 10 – Francis Colas – git basics Standard commands Basic commands Initialization: I git init <name>: initialize an empty repository , I git clone <url>: clone a repository, Manipulating the staging area: I git add <files>: add current state of files to next commit, I git rm <files>: delete files, I git mv <oldname> <newname>: move/rename a file. Looking at status: I git status: list state of working copy with respect to last commit. Commit and transmission: I git commit -m "commit message": record changes into a commit, I git pull [<url|remote>]: get changes and merge them, I git push [<url|remote>]: sends commit to remote/url. 10 – Francis Colas – git basics Standard commands Branching commands Handling branches (because it’s cool): I git branch <branch>: create branch, I git branch -d <branch>: delete a branch, I git checkout <branch>: change to a different branch, I git checkout -b <branch>: create and change to branch, I git push -u <remote> <branch>: create and push branch to remote, I git merge <branch>: merge changes of the given branch into the current one (used by pull). 11 – Francis Colas – git basics Standard commands Additional information Temporary changes: I git stash: save current changes aside, I git stash pop: restore saved changes. Seeing branches and commits: I gitk [--all]: good tool when lost in branches, I git gui: makes it easy to pick individual changes in a file. Ignore file: I .gitignore: list of patterns of filenames that will be ignored. Fixing the last commit before sending it: I git commit --amend: replaces commit with current staging area. 12 – Francis Colas – git basics 04 Feature branch workflow Advantages: I master always consistent and (hopefully) working, I less merges while concurrent development, I easier to manage, I interesting commit tree. :-) Merging: I open merge request, I have somebody review changes, I ideally review and test code before accepting merge. Feature branch workflow Feature branch workflow General idea: I features get developed in individual branches, I when ready: merge into master branch, 14 – Francis Colas – git basics Merging: I open merge request, I have somebody review changes, I ideally review and test code before accepting merge. Feature branch workflow Feature branch workflow General idea: I features get developed in individual branches, I when ready: merge into master branch, Advantages: I master always consistent and (hopefully) working, I less merges while concurrent development, I easier to manage, I interesting commit tree. :-) 14 – Francis Colas – git basics Feature branch workflow Feature branch workflow General idea: I features get developed in individual branches, I when ready: merge into master branch, Advantages: I master always consistent and (hopefully) working, I less merges while concurrent development, I easier to manage, I interesting commit tree. :-) Merging: I open merge request, I have somebody review changes, I ideally review and test code before accepting merge. 14 – Francis Colas – git basics Feature branch workflow Practically In practice: I git checkout -b new_feature I code, test, code more, test even more... I git status I git add <files> I git status I git commit -m "new feature" I git pull I git push -u origin new_feature I merge request I get it accepted I git checkout master I git pull I git branch -d new_feature I git remote prune origin 15 – Francis Colas – git basics Feature branch workflow Merge request From the command line: I git stash I git checkout master I git checkout -b merging_new_feature I git fetch I git merge new_feature I code review I test (compilation, unit tests, etc.) I git checkout master I git merge new_feature I git push I git checkout your_branch I git stash pop 16 – Francis Colas – git basics 05 Conclusion Conclusion Conclusion git: I not complex to use, I good for one or many people, I good for connected or offline work; Feature branch model: I convenient in big projects, I state-of-the-art use of git. 18 – Francis Colas – git basics + Thanks for your attention. 18 – Francis Colas – git basics.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    24 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us