Assumptions. GIT Commands. OS Commands

Similar documents
git commit --amend git rebase <base> git reflog git checkout -b Create and check out a new branch named <branch>. Drop the -b

Submitting your Work using GIT

2 Initialize a git repository on your machine, add a README file, commit and push

Revision control. INF5750/ Lecture 2 (Part I)

Git, the magical version control

Computer Science Design I Version Control with Git

Git. Presenter: Haotao (Eric) Lai Contact:

1/20/13 Git tutorial. Git tutorial. Mike Nolta. file:///users/nolta/github/reveal.js/git.html?print-paper#/ 1/31

GIT FOR SYSTEM ADMINS JUSTIN ELLIOTT PENN STATE UNIVERSITY

How to version control like a pro: a roadmap to your reproducible & collaborative research

GIT Princípy tvorby softvéru, FMFI UK Jana Kostičová,

Outline The three W s Overview of gits structure Using git Final stuff. Git. A fast distributed revision control system

Git Introduction CS 400. February 11, 2018

Windows. Everywhere else

Algorithm Engineering

Git. A fast distributed revision control system. Nils Moschüring PhD Student (LMU)

Version Control System - Git. zswu

Version Control. Version Control

1. Git. Robert Snapp

Introduction to Version Control

Git Tutorial. André Sailer. ILD Technical Meeting April 24, 2017 CERN-EP-LCD. ILD Technical Meeting, Apr 24, 2017 A. Sailer: Git Tutorial 1/36

Version Control. Version Control

Index. Alias syntax, 31 Author and commit attributes, 334

Software Revision Control for MASS. Git Installation / Configuration / Use

Version Control: Gitting Started

Git. Charles J. Geyer School of Statistics University of Minnesota. Stat 8054 Lecture Notes

git the SCM system Jan-Simon Möller training.linuxfoundation.org

LAB MANUAL GIT BY PRATIK JAIN. To start with git bash, we need to authenticate ourselves so that for every commit, git can use this information.

Introduction to distributed version control with git

Versioning with git. Moritz August Git/Bash/Python-Course for MPE. Moritz August Versioning with Git

Git version control with Eclipse (EGit) Tutorial

Git Tutorial. Version: 0.2. Anders Nilsson April 1, 2014

Common Git Commands. Git Crash Course. Teon Banek April 7, Teon Banek (TakeLab) Common Git Commands TakeLab 1 / 18

git Version: 2.0b Merge combines trees, and checks out the result Pull does a fetch, then a merge If you only can remember one command:

USING GIT FOR AUTOMATION AND COLLABORATION JUSTIN ELLIOTT - MATT HANSEN PENN STATE UNIVERSITY

Git Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : October, More documents are freely available at PythonDSP

! #Running this command from the top directory of your project will add all your changes."! $ git add."

Version Control with GIT

A Brief Introduction to Git. Sylverie Herbert (based on slides by Hautahi Kingi)

Intermediate Programming, Spring Misha Kazhdan

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read)

Working with GIT. Florido Paganelli Lund University MNXB Florido Paganelli MNXB Working with git 1/47

Software Project (Lecture 4): Git & Github

Introduction to Git and GitHub for Writers Workbook February 23, 2019 Peter Gruenbaum

Git. A Distributed Version Control System. Carlos García Campos

Git. CSCI 5828: Foundations of Software Engineering Lecture 02a 08/27/2015

Gitting things done. Hands-on introduction to git niceties. Jan Urbański Ducksboard

Using Git to Manage Source RTL

213/513/613 Linux/Git Bootcamp. Cyrus, Eugene, Minji, Niko

CPSC 491. Lecture 19 & 20: Source Code Version Control. VCS = Version Control Software SCM = Source Code Management

G E T T I N G S TA R T E D W I T H G I T

Beyond git add/commit/push

MOOSE-Based Application Development on GitLab

GIT. CS 490MT/5555, Spring 2017, Yongjie Zheng

VCS VERSION CONTROL SYSTEMS

Source Code Management wih git

Version Control. Software Carpentry Github s Hello World Git For Ages 4 And Up You need source code control now

Git better. Collaborative project management using Git and GitHub. Matteo Sostero March 13, Sant Anna School of Advanced Studies

GETTING STARTED WITH. Michael Lessard Senior Solutions Architect June 2017

DEAD-SIMPLE VERSION CONTROL FOR YOUR TEAM GIT WITH MATTHEW REIDSMA GRAND VALLEY STATE UNIVERSITY

Tutorial: Getting Started with Git. Introduction to version control Benefits of using Git Basic commands Workflow

Crash Course in C++ R F L Evans. www-users.york.ac.uk/~rfle500/

Push up your code next generation version control with (E)Git

Tools for software development:

6 Git & Modularization

Version control. what is version control? setting up Git simple command-line usage Git basics

Eugene, Niko, Matt, and Oliver

Agenda. Several projects are using GIT Developer(s) Junio Hamano, Linus Torvalds. Qt Stable release (January 31, 2011)

Introduction to GIT. Jordi Blasco 14 Oct 2011

Lab Exercise Git: A distributed version control system

Git tutorial. Katie Osterried C2SM. October 22, 2015

FEEG Applied Programming 3 - Version Control and Git II

Version Control with Git

CESSDA Expert Seminar 13 & 14 September 2016 Prague, Czech Republic

Version control with git and Rstudio. Remko Duursma

Revision Control and GIT

[Software Development] Development Tools. Davide Balzarotti. Eurecom Sophia Antipolis, France

GUIDE TO MAKE A REAL CONTRIBUTION TO AN OPEN SOURCE PROJECT 1. 1

TDDC88 Lab 4 Software Configuration Management

Barry Grant

Software Development I

EECS 470 Lab 4. Version Control System. Friday, 31 st January, 2014

Project Management. Overview

Introduction to Version Control using Git

Git. It is easy to shoot your foot off with git, but also easy to revert to a previous foot and merge it with your current leg.

Github/Git Primer. Tyler Hague

L Modeling and Simulating Social Systems with MATLAB

GETTING TO KNOW GIT: PART II JUSTIN ELLIOTT PENN STATE UNIVERSITY

Chapter 5. Version Control: Git

GIT VERSION CONTROL TUTORIAL. William Wu 2014 October 7

Topics covered. Introduction to Git Git workflows Git key concepts Hands on session Branching models. Git 2

About SJTUG. SJTU *nix User Group SJTU Joyful Techie User Group

Version Control Systems

Tutorial 2 GitHub Tutorial

Outline. Version Control System (VCS) basics Git terminology & concepts Basic Git commands Branches in Git Git over the network (time permitting)

Git and GitHub. Dan Wysocki. February 12, Dan Wysocki Git and GitHub February 12, / 48

A BASIC UNDERSTANDING OF VERSION CONTROL

Advanced Operating Systems Control Versioning with GIT. Giuseppe Massari

What is git? Distributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development;

Git. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

Transcription:

Many of the world s largest dev teams have adopted Git and it s not hard to see why It can handle small and large projects easily It has a tiny footprint It outclasses other version control tools It s simple to learn We ll take that last bullet with a pinch of salt Git 101 is designed to give you all the basics of git in 15 minutes, through a combination of this tutorial, and the accompanying cheat sheet, you should have everything you need to start learning to use Git. This tutorial walks through how to create a new Git repository, make changes to it, and keep track of changes. GIT Commands Git commands to type in your terminal are highlighted in bold, e.g. git status. OS Commands OS commands are also entered on the command line and are highlighted in red, e.g. cd <directory>. Assumptions Git is installed (if not, download it here) You are using the command line terminal, or git bash for windows as your Git client. page 1 - git 101 presented by clearvision

What this whitepaper won t tell you This whitepaper will give you enough to get started, but we recommend a Git training course to truly get to grips with all the features and functionality that Git will bring to you and your organisation. We run courses ranging from basic to admin. Let's start from the very beginning... Creating a new repository

Creating a new repository When history is added to a Git repository it is important for audit purposes that Git knows who the author of these changes are. So the first thing you are going to need to do is to tell Git who you are. Git will need this information regularly, every time you create history in fact. By configuring these settings to start we can save ourselves a lot of time later. git config --global user.name myname The author is configured as both a username, which we have set here, and an email address, which we set below git config --global user.email myemail The global argument here (and above) applies myname to all local Git repositories you use (not those used by others who share the system) In your users home directory type the following commands: mkdir git_repos - If you do not already have a location for your local Git repositories) cd git_repos - To move to the newly created directory. git innit newrepo This creates a directory called newrepo and initialises it as a Git repository. Inside the new directory is a hidden directory named.git WARNING Until you are comfortable with Git DO NOT modify the contents of this directory, as this is where Git keeps track of things (that s why it s hidden!). In most cases, Git will manage the contents of this directory for you. page 3 - git 101 presented by clearvision

Making Changes Let s create some content within newrepo : cd ~/git_repos/newrepo - Change directory to newrepo if you re not already there. echo red > red.txt - Create a file called red.txt containing the word red. git status The status command shows the status of our working directory and our staging area in comparison to the contents of the repository. At this point we can see that Git is aware that there is a new file red.txt however it is not being tracked as yet. git add red.txt The add command takes content from our Working Directory (in this case red.txt ) and adds it to the Staging Area. This has the side effect of telling git to track changes to the file. git status The status has now changed and you can see that Git is tracking red.txt (along with a handy hint to untrack it). git commit -m added file red.txt Now we committed our new file from the Staging Area to our Local Repository database. The -m option here allows us to specify a commit message to identify what the commit is for, if it is omitted then the default editor will appear for the message to be entered. All git commits must include data on both the author (which we configured earlier) and a commit message - it cannot be blank. git status We are now in the situation where our Working Directory is clean. That doesn t mean it is empty, it means that our Local Repository and our Working Directory are in step. page 4 - git 101 presented by clearvision

Now let s modify red txt and create another new file : echo red >> red.txt - Append a new line containing red at the end of file red.txt. echo blue > blue.txt - Which creates the new file blue.txt containing the text blue. We now have two files in our Working Directory. As yet we have not asked Git to track our new file. Let s do that now. git add blue.txt Git is now tracking blue.txt, and the changes have been added to the staging area. git add red.txt Although Git is already tracking red.txt, we must still add our changes into the staging area. This allows us to plan for the next commit before we create new history. git status Git shows us we have two changes ready for commit, one new file and one modified file. git commit -m Modifying red and adding blue Git has now committed our changes from the Staging Area to our Local Repository. Next Viewing History

viewing history git log -5 Git is now showing us our commit history (to the last 5 commits). We can see we have created two commit points. Each commit has a 40 character hash which uniquely identifies it, who did it, when it happened and our (hopefully) meaningful message as to why. This hash is important, there are no sequential revision numbers in git so it provides our only unique identification method. Sharing code with others It s more likely, when you begin working you won t create your own repository, you ll copy a project that exists elsewhere through the command git clone. In this scenario git maintains a link back to the original repository which is named origin. As we started from scratch we don t have this link and must create it. git remote add origin URL/to/repository Define the location of origin as another repository which is reachable via a URL. git push -u origin --all Push the contents we have created up to the remote repository configured as origin - note that this assumes we are using the default master branch, or another branch that also exists in the remote repository. page 6 - git 101 presented by clearvision

You're good to go! You have now reached the end of this Git 101 tutorial. You can use the accompanying cheat sheet to remind yourself of the use cases for each of these commands, and a few more you might find useful as well! Alternatively, if you are interested in understanding this tutorial in much greater detail, or want to take your learning further, Clearvision offer a range of training courses which can help, contact us now at sales@clearvision-cm.com. other resources As an open source platform, Git has an almost infinite amount of support available online. We ve selected some of the best: Git training courses (Basics, Advanced & Admin) Comprehensive courses run via webinar or in a classroom. Git consultants - Support with configuration and implementation, as well as Git health checks and bespoke help with Git. Git-SCM A great resource for downloads and up to date documentation. Git Blogs Our team produce regular content for the CV Blog under the Git category. Atlassian s Git guide Atlassian s tutorial is a nice visual guide to Git. Plus:

Infrastructure references HEAD Current working position, as shown by the contents of your working directory. master Default branch. origin Default upstream repository. origin/master Remote branch tracking the location of the master branch in the origin repository. HEAD^ or HEAD~n An ancestor of the current head where ^ = 1 or n = any number above 1. create git innit <path> Turns the directory at <path> into a git repository, even if not empty. If <path> does not exist, this command will create it. git clone <../existing/repo/path> <../new/ repo/path> Copies the repository at <../existing/repo/path> to <../new/ repo/path> and records <../existing/repo/path> as the origin change git add <file> Stages a change to be included in the next commit. git add * or git add. Stages all changes. git add -u. Stages all local modifications, (recursively from the current directory, does not work on new (untracked) files. git add -u :/ Stages all local modifications from the repository root, does not work on new (untracked) files. git add -A Stages all local modificaions. git commit Converts staged changes into binary objects and puts a new commit at the top of current branch. git commit -m <message> Converts staged changes into binary objects and puts a new commit at the top of current branch with comment <message>. git commit -a Stages all local modifications and commits (does not work on new files). git commit <file(s)> Creates a new commit ignoring all changes other than <file(s)>. git rm <file> Deletes <file> and stages the change. git mv <file> <newfile> Move or rename <file> to <newfile>. git stash save/apply Save or re-apply local modifications to / from a stash.

fixing errors git commit --amend git revert <SHA-1> (correct the staging area first). the current branch. git reset <file> git checkout <SHA-1> <file> Creates a new commit in place of the current HEAD Unstage <file>. Revert the delta of <SHA-1> creating a new commit at the top of recover <file> from specific commit <SHA-1>. git reset --hard Resets all modifications back to the HEAD, this cannot be undone unless you Stash first. log diff git log (-n) git status Shows the history of the current branch to the (nth) Show any changes in the working directory and/or index. ancestor. git diff git log -p <file> Show changes to unstaged files. Shows the history of <file>. git diff --cached git show <SHA-1> Show changes to staged files. Show details of the object with the id <SHA-1>. git diff <SHA-1> git show <SHA-1>:<file> Show changes since <SHA-1>, this can also be HEAD or Show details of <file> referenced by commit <SHA-1>. <branch>. git blame <file> git diff <SHA-1><SHA-1> Show details of who changed <file> and when on a line by Compare two commits. line basis. Branching & merging updates git checkout <SHA-1> git fetch <remote> git merge <branch> git pull <remote> Switch to the <SHA-1> or replace with a <branch>. Merge <branch> into current branch. Recover remote changes to remote branches <remote>. Recover remote changes to remote branches from <remote> and merge to local versions. git branch <branch> Create branch named <branch> based on the HEAD. git push <remote> <branch> send local changes up to remote server <remote> git checkout -b <branch> <branch>. Create branch <branch> based on <SHA-1> and switch to it. git branch -d Delete branch <branch>. Brought to you by: clearvision-cm.com/git