Mastering Git Mastering Computer Science Series Editor: Sufyan bin Uzayr Mastering Git: A Beginner’s Guide Sumanna Kaul, Shahryar Raz, and Divya Sachdeva Mastering Ruby on Rails: A Beginner’s Guide Mathew Rooney and Madina Karybzhanova Mastering Sketch: A Beginner’s Guide Mathew Rooney and Md Javed Khan Mastering C#: A Beginner’s Guide Mohamed Musthafa MC, Divya Sachdeva, and Reza Nafim Mastering GitHub Pages: A Beginner’s Guide Sumanna Kaul and Shahryar Raz Mastering Unity: A Beginner’s Guide Divya Sachdeva and Aruqqa Khateib For more information about this series, please visit: https:// www.routledge.com/Mastering-Computer-Science/ book-series/MCS The “Mastering Computer Science” series of books are authored by the Zeba Academy team members, led by Sufyan bin Uzayr. Zeba Academy is an EdTech venture that develops courses and content for learners primarily in STEM fields, and offers education consulting to Universities and Institutions worldwide. For more info, please visit https://zeba.academy Mastering Git A Beginner’s Guide Edited by Sufyan bin Uzayr First edition published 2022 by CRC Press 6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742 and by CRC Press 2 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN CRC Press is an imprint of Taylor & Francis Group, LLC © 2022 Sufyan bin Uzayr Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, access www. copyright.com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not available on CCC please contact [email protected] Trademark Notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification and explanation without intent to infringe. ISBN: 9781032134161 (hbk) ISBN: 9781032134154 (pbk) ISBN: 9781003229100 (ebk) DOI: 10.1201/9781003229100 Typeset in Minion by KnowledgeWorks Global Ltd. Contents About the Editor, xiii Chapter 1 ◾ Getting Started 1 VERSION CONTROL BASICS 2 WHAT IS GIT? 9 ADVANTAGES OF GIT 15 For Development 16 Git for Marketing 17 Git for Product Management 17 Git for Designing 18 Git for Customer Support 19 Git for HR 19 Git for Budget Management 19 DISADVANTAGES OF GIT 19 HISTORY OF GIT 26 REFERENCES 33 v vi ◾ Contents Chapter 2 ◾ The Basics 35 INSTALLING GIT 35 FIRST TIME GIT SET UP 39 Establishing Your Identity 41 Editing 41 Default Branch Name 42 Check the Settings 42 Creating a New Repo 44 Git Clone 44 Saving Changes 45 Git Push 45 Bare and Cloned Repositories 46 Reverting Changes 46 TIPS AND TROUBLESHOOTING 47 Chapter 3 ◾ Working with Repositories 57 WHAT ARE GIT REPOSITORIES? 58 RECORDING CHANGES TO REPOS 60 WORKING WITH REMOTES 67 GIT ALIASES 72 TAGGING 80 How to List Your Tags? 80 Creating Tags 81 Annotated Tags 82 Lightweight Tags 82 Tagging Later 82 Contents ◾ vii Sharing Tags 83 Deleting Tags 83 Check Out the Tags 84 Retagging or Replacing Old Tags 85 Chapter 4 ◾ Working with Branches 87 WHAT ARE BRANCHES? 88 Working 90 Common Commands 91 Creation of Branches 91 Creation of Remote Branches 92 Deleting Branches 92 BRANCHING AND MERGING 93 Definition of Git Branching 93 Branch Naming 95 BRANCH WORKFLOWS 99 How It Works 100 Beginning with the Main Branch 101 Creating a New Branch 101 Subsequent Tasks 101 Push Feature Branch to Remote 101 Resolve Feedback 102 Merge Your Pull Request 102 Pull Requests 102 REMOTE BRANCHES 106 Pushing 108 viii ◾ Contents Tracking Branches 109 Pulling 111 Deleting the Remote Branches 111 Chapter 5 ◾ Working with Servers 113 GETTING GIT ON SERVER 114 Putting the Bare Repository on a Server 114 Small Setups 115 SSH Access 116 SERVER SETUP 117 DISTRIBUTED GIT AND PROJECTS 119 Distributed Workflow 120 Centralized Workflow 120 Integrator-Manager Workflow 121 Dictator and Lieutenants Workflow 123 Contributing to Projects 124 Commit Guidelines 126 Chapter 6 ◾ GitHub 129 WHAT IS GITHUB? 129 Account Set Up and Configuration 131 SSH Access 134 Your Avatar 135 Email Addresses 135 Two-Factor Authentication 136 Contents ◾ ix HISTORY OF GITHUB 137 Acquired by Microsoft 139 Mascot 141 HOW TO USE GITHUB 144 How to Create a Repository on GitHub? 144 Create Branches 145 Making Commits 146 Pull Command 147 Merge Command 148 Cloning and Forking GitHub Repository 148 DIFFERENT TYPES OF ACCOUNTS 149 Personal User Accounts 149 Organization Accounts 150 Enterprise Accounts 151 Chapter 7 ◾ GitLab 153 WHAT IS GITLAB 153 HISTORY OF GITLAB 155 HOW TO USE GITLAB 161 GitLab and SSH Keys 161 Prerequisites 162 Supported SSH Key Types 162 Generating the SSH Keys 163 Configure Your SSH to Point to a Different Directory 164 Updating Your SSH Key Passphrase 165