Version Control with Git and GitHub

42 Slides9.00 MB

Version Control with Git and GitHub

What’s the plan for today? 1. 2. 3. 4. Version Control - Concepts, Terminology Git – Commands Collaborating with Git using GitHub Version Control practices and workflow in the industry.

How do you work with other developers? Work in a team, probably on particular components ? Integrate your code together. Make copies of your files in case something you lose them. (Not really?)

How do you work with other developers? Work in a team, probably on particular components ? Integrate your code together. Make copies of your files in case something you lose them. (Not really?)

So what’s version control? Version control is the management of changes to documents, primarily computer programs. Also known as revision control or source control. Examples: git, mercurial, subversion

Why version control? Makes working in a team easy! 1. Code without interference. 2. Go back to a previous version (iOS 10 anyone?) 3. Integrate code of multiple developer’s easily. 4. Know who did what, when. Keep your code secure.

Do you really need version control?

Do you really need version control?

Git A distributed version control system Command-Line Tool (accessible with Terminal on the Mac or Git Bash on Windows)

Why Git and not other VCS? Git’s the most popular version control system in the industry, by far. A proper and detailed understanding of Git will allow you to make a transition to any other distributed VCS easily. Most popular VCS are similar to Git

Installing Git Things you’ll need: 1. You need Git installed on your system, and you can access it in a UNIX Terminal, either the Terminal on the Mac or Git Bash on Windows. 2. Download Git from the following link: https://git-scm.com/downloads

Version Control Terminology 1. 2. 3. 4. 5. 6. 7. 8. Version Control System (VCS) or (SCM) Repository Commit SHA Working Directory Checkout Staging Area/Index Branch

Version Control Terminology 1. Version Control System : A VCS allows you to: revert files back to a previous state, revert the entire project back to a previous state, review changes made over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more. 2. Repository: A directory that contains your project work which are used to communicate with Git. Repositories can exist either locally on your computer or as a remote copy on another computer.

Version Control Terminology 3. Commit Git thinks of its data like a set of snapshots of a mini file system. Think of it as a save point during a video game. 4. SHA A SHA is basically an ID number for each commit. Ex. E2adf8ae3e2e4ed40add75cc44cf9d0a869afeb6 5. Working Directory The files that you see in your computer's file system. When you open your project files up on a code editor, you're working with files in the Working Directory.

Version Control Terminology 6. Checkout When content in the repository has been copied to the Working Directory. It is possible to checkout many things from a repository; a file, a commit, a branch, etc. 7. Staging Area You can think of the staging area as a prep table where Git will take the next commit. Files on the Staging Index are poised to be added to the repository. 8. Branch A branch is when a new line of development is created that diverges from the main line of development. This alternative line of development can continue without altering the main line.

Let’s dive into the good stuff now GIT COMMANDS: (THINGS WE’LL COVER) BASIC GIT COMMANDS REMOTE REPOSITORY – PUSH & PULL BRANCHING, TAGGING AND MERGING DISASTER HAS STRUCK!

Basic Git Commands git init git status git add filename / git add . git commit / git commit –m “commit message” git log –oneline / git log —stat git clone Other commands like git show, git ignore, git diff etc.

Demo

Basic Git model locally

Basic Git Commands git init – Initialize a Git repository/working directory git status – Status of your working directory git add filename or git add . (for all files in your working directory) git commit – Stash changes in your working directory git log –oneline – View your commit history git clone – Create an identical copy

GitHub It’s a hosting medium/website for your Git repositories Offers powerful collaborative abilities A good indicator of what you code/how much you code/quality of your code

Working with a remote repository Remote? It’s the place where your code is stored. By default, remote name is origin and default branch is master. Certain things that come to play, namely collaboration. How are we going to handle that with Git. So here comes, push, pull, branching, merging, forking.

Alice

Alice Bob

Alice Joe Bob

Alice Bob Joe Who replaced the files? When ?

How to access GitHub 1. Access it on github.com 2. Create an account if you don’t already have one. 3. GitHub Clone link: github.com/intley/Version Control Workshop

GitHub Demo

More Git commands git push – push your changes into the remote repository git pull – pull your latest changes from the remote repository git branch – view branches in your repository git branch branchname - create a branch git checkout branchname - move to that branch git merge branchname - merge into that branch git revert commit sha

Demo

Collaboration with GitHub Remote Repo Master Alice C1 C2 Bob

Collaborate Remote Repo git clone git clone Alice Master Master Master C1 C1 C1 C2 C2 C2 Bob

Collaborate Remote Repo Alice Master Master Master C1 C1 C1 C2 C2 C2 CA git add git commit CB Bob git add git commit

Collaborate Remote Repo Master Alice Master Master C1 C1 C2 C2 C2 CA C3 CB C1 git push Bob

Collaborate Remote Repo Alice Master Master Master C1 C1 C2 C2 C2 CA C3 CB git fetch C1 Bob C3

Collaborate Remote Repo Alice Master Master C1 C1 C2 C2 CA C3 Master git merge C1 C2 C3 CB Bob

Collaborate Remote Repo Alice Master Master C1 C1 C2 C2 C2 CA C3 C3 CB Master git push C1 CB Bob

Collaborate Remote Repo Master Alice Master Master C1 C1 C2 C2 C2 CA C3 C3 CB CB CB C1 git pull Bob

More on Collaborative Git commands Deleting a branch git branch –d branchname Merge conflicts! How do you resolve? Pull requests ? git tag –a v1.0 / git tag –a v1.0 commit sha

Dealing with Merge Conflicts Two typical cases of merge conflicts 1. Normal merge where you’re a collaborator 2. Pull request (handled by the repository owner)

More to learn in Git/Forward Steps Firstly, I highly recommended building a project from scratch with Git integrated and if possible, with other programmers. As far as Git goes, this PowerPoint covers the basics to help you get started, but as you work with version control, you will encounter new commands required. Rebasing – concept you could cover.

Questions? Contact me ([email protected] if you have questions) Happy to help!

Back to top button