├── img ├── .DS_Store ├── git-cli.png ├── git-branch.png ├── git-change.png ├── git-clone.png ├── git-commit.png ├── git-fork.png ├── git-hello-1.png ├── git-hello-2.png ├── git-homepage.png ├── git-profile.png ├── git-hello-3-b1.png ├── git-hello-4-b2.png ├── git-hello-6-b1.png ├── git-hello-7-b2.png ├── git-hello-diff.png ├── git-repo-create.png ├── git-commit-history.png ├── git-hello-5-merged.png └── git-new-repo-clone.png ├── exercise2 └── README.md ├── exercise1 └── README.md ├── exercise3 └── README.md ├── LICENSE └── README.md /img/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/.DS_Store -------------------------------------------------------------------------------- /img/git-cli.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-cli.png -------------------------------------------------------------------------------- /img/git-branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-branch.png -------------------------------------------------------------------------------- /img/git-change.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-change.png -------------------------------------------------------------------------------- /img/git-clone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-clone.png -------------------------------------------------------------------------------- /img/git-commit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-commit.png -------------------------------------------------------------------------------- /img/git-fork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-fork.png -------------------------------------------------------------------------------- /img/git-hello-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-hello-1.png -------------------------------------------------------------------------------- /img/git-hello-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-hello-2.png -------------------------------------------------------------------------------- /img/git-homepage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-homepage.png -------------------------------------------------------------------------------- /img/git-profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-profile.png -------------------------------------------------------------------------------- /img/git-hello-3-b1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-hello-3-b1.png -------------------------------------------------------------------------------- /img/git-hello-4-b2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-hello-4-b2.png -------------------------------------------------------------------------------- /img/git-hello-6-b1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-hello-6-b1.png -------------------------------------------------------------------------------- /img/git-hello-7-b2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-hello-7-b2.png -------------------------------------------------------------------------------- /img/git-hello-diff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-hello-diff.png -------------------------------------------------------------------------------- /img/git-repo-create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-repo-create.png -------------------------------------------------------------------------------- /img/git-commit-history.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-commit-history.png -------------------------------------------------------------------------------- /img/git-hello-5-merged.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-hello-5-merged.png -------------------------------------------------------------------------------- /img/git-new-repo-clone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InsightDataScience/github-tutorial/master/img/git-new-repo-clone.png -------------------------------------------------------------------------------- /exercise2/README.md: -------------------------------------------------------------------------------- 1 | # exercise 2 2 | 3 | # Purpose 4 | In several cases you will encounter files that don't belong in the repository. Typical examples include: 5 | * credentials (passwords, usernames, keys) 6 | * cached files (.pyc) 7 | 8 | Git allows users to add a .gitignore file to their top level directory to ignore these specific files 9 | 10 | # Tasks 11 | 1. create a file in your repository called `my_super_secret_stuff.txt` 12 | 2. run a `git status` and see that `my_super_secret_stuff.txt` is untracked but can be added 13 | 3. create a `.gitignore` file if it does not already exist in your top level directory 14 | 4. at the top, add `my_super_secret_stuff.txt` to the file and save it 15 | 5. run a `git status` and see that `my_super_secret_stuff.txt` doesn't show up anymore! 16 | 6. `git add` your changes 17 | 7. `git commit` with a useful message 18 | 8. `git push` to the remote repository 19 | 20 | -------------------------------------------------------------------------------- /exercise1/README.md: -------------------------------------------------------------------------------- 1 | # exercise 1 2 | 3 | # Purpose 4 | Practice adding, committing, and pushing files using git to GitHub 5 | 6 | # Tasks 7 | 1. create a file called `exercise1.py` 8 | 2. create a function in the file called `print_message` that prints a message when called. Save the file. 9 | 3. `git add` your changes 10 | 4. `git commit` with a useful message 11 | 5. `git push` to the remote repository 12 | 6. Create a function in the file called `print_art` that prints an ascii art image when called. Save the file. 13 | 7. `git add` your changes 14 | 8. `git commit` with a useful message 15 | 9. `git push` to the remote repository 16 | 10. Create a function in the file called `hi_fellow` that takes the input "I am an Insight Fellow!" and returns the message "That's awesome! How is that random forest model going?" 17 | 11. `git add` your changes 18 | 12. `git commit` with a useful message 19 | 13. `git push` to the remote repository 20 | -------------------------------------------------------------------------------- /exercise3/README.md: -------------------------------------------------------------------------------- 1 | # exercise 3 2 | 3 | # Purpose 4 | Create a GitHub repo for your Insight project and add, commit, and push a change. 5 | 6 | # Tasks 7 | 1. create a new repo on GitHub for your Insight project. 8 | 2. in your development folder, `git clone` this project repo to your local machine. 9 | 3. open a file and make a change (finish that function you were working on before this tutorial!). 10 | 4. `git add` your changes 11 | 5. `git commit` with a useful message 12 | 6. `git push` to the remote repository 13 | 7. repeat steps 3 and 4 until your project is done! 14 | 15 | # Advanced Tasks 16 | Say you have a working version of your project, but you want to make some changes. But you're afraid that if you make a change to your project, it will break and be difficult to recover the original working version. This is where git comes to the rescue! 17 | 18 | If you want to add a feature or debug a bug on a working version of your project, create a new branch to work on that feature or bug. This means you can have a working version available to you while you continue to develop on the project. 19 | 20 | Test the new branch. If you are satisfied with your changes, merge the branch with your original branch. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # github-tutorial 2 | 3 | # Git and GitHub 4 | 5 | ### What? 6 | - **Git:** a version control system that keeps track of code changes 7 | - **GitHub:** a popular web-based server for hosting repositories 8 | 9 | ### Why? 10 | - Keeps a full history of changes 11 | - Allows multiple programmers to work on the same codebase 12 | - Is efficient and lightweight (records file changes, not file contents) 13 | - Public repositories on GitHub can serve as a coding resume. 14 | 15 | ### How? 16 | - That's what this session is for! 17 | 18 | # Git and GitHub Setup 19 | 20 | ### 1. Create a GitHub account 21 | 22 | Create a Github account through the Github website. 23 | 24 | - Go to https://github.com/ and follow on-screen instructions to create a user account 25 | 26 | - Tip: Choose a job-appropriate user name if possible 27 | 28 | 29 | 30 | ### 2. Install Git 31 | 32 | Install Git on your computer (through Terminal for Mac or Ubuntu). 33 | 34 | - Installing on Mac: `$ brew install git` 35 | - Installing on Ubuntu: `$ apt-get install git` 36 | - Installing on Windows: [http://git-scm.com/downloads](http://git-scm.com/downloads) 37 | 38 | - Tip: If you are running into trouble, try [here](http://git-scm.com/book/en/Getting-Started-Installing-Git) 39 | - Tip: To check if git is already installed, try `$ git` in Terminal 40 | 41 | ![git-cli](img/git-cli.png) 42 | 43 | ### 3. Configure Git 44 | 45 | Configure Git so that Github can recognize your commits (in Terminal). 46 | 47 | - Run the following commands in Terminal to configure git: 48 | 49 | `$ git config --global user.name "[insert your user name here]"` 50 | `$ git config --global user.email "[insert your email here]"` 51 | 52 | - Tip: The gloabl config settings can be accessed and manually edited in `~/.gitconfig` 53 | 54 | ### 4. Fork the tutorial repository to your account 55 | 56 | Fork the tutorial repository to your account through the Github webpage. This makes a copy of the original repository on your account. 57 | 58 | - On the [GitHub repo page](https://github.com/InsightDataScience/github-tutorial), in the top right corner of the page under the photo of your account, click the Fork button (see below for example). 59 | - Select your account when prompted. This should fork the github-tutorial repository to your account. 60 | 61 | Tip: If you successfully forked the tutorial repository, you should see the name of the repository as [your user name]/github-tutorial 62 | 63 | ![git-fork](img/git-fork.png) 64 | 65 | ### 5. Clone the repository to your local machine 66 | 67 | Clone this repository (the remote repository) to your local machine. 68 | 69 | - On your tutorial repository webpage, click the green "Clone or download" button on the right side of the page. 70 | - Select the "Use HTTPS" option if it is available. 71 | - Copy the link. 72 | 73 | - In Terminal, navigate to your development folder. (Note: If you don't have a development folder, it may be a good idea to create one where you can store all directories tracked by git in one place.) 74 | 75 | `$ cd [path to your development folder]` 76 | 77 | - Type `git clone` into Terminal, followed by the repository link you copied (see below for example) 78 | 79 | `$ git clone [link to your forked tutorial repository]` 80 | 81 | 82 | 83 | ### You are now ready to use version control with Git and Github! 84 | 85 | # Git Concepts and Vocabulary 86 | 87 | ### Change (aka Diff) 88 | 89 | Git maintains version control by tracking the changes or diffs between file versions. 90 | 91 | You can change a file by doing one of two things: 92 | 1. File creation, renaming, or deletion. 93 | 2. Insertion or deletion of a line in a file (a modified line is both an insertion and a deletion) 94 | 95 | Git represents insertions or added changes with a `+` and deletions or removed changes with a `-` 96 | 97 | ![git-hello-diff](img/git-hello-diff.png) 98 | 99 | Tip: You can use the command `git diff` to see how a file has changed since its last commit or between two branches. 100 | 101 | ### Commit 102 | 103 | Commits are a series of changes that records incremental updates to a series of files. 104 | 105 | Each commit a global unique hash (calculated from contents of file) that serves as an identifier. 106 | 107 | ![git-commit](img/git-commit.png) 108 | 109 | ### Branch 110 | 111 | A branch refers to a linear series of commits. 112 | 113 | A codebase can be calculated by applying changes to files in each commit in succession. 114 | 115 | ![git-commit-history](img/git-commit-history.png) 116 | 117 | ### Repository 118 | 119 | A repository refers to a tree structure that contains many branches. Each branch represents a different state of the code. 120 | 121 | Branches can be formed at any commit, and two branches can be merged together by summing their changes (assuming there are no conflicts). 122 | 123 | # Basic Git Tutorial 124 | 125 | ## Basic Workflow 126 | 127 | There are three basic commands that part of the typical workflow when doing version control with git. These commands are **add, commit and push**. 128 | 129 | ### 0. Create a file 130 | 131 | First, create an example file to track using Git. 132 | 133 | - In Terminal, navigate to your repository folder. 134 | - Create a Python file called `hello.py` using your favorite editor 135 | - Write some (very simple) code and save the file. 136 | 137 | ``` 138 | def hello(name): 139 | print("Hello " + name) 140 | 141 | if __name__ == "__main__": 142 | hello() 143 | ``` 144 | 145 | ### 1. git add 146 | 147 | After creating the file, add the file to be tracked using Git. 148 | 149 | - In Terminal, use `git add` followed by the filename to add the file to be tracked. 150 | 151 | `$ git add hello.py` 152 | 153 | ### 2. git commit 154 | 155 | After adding the file to be tracked, commit the changes to be tracked using Git. 156 | 157 | - In Terminal, use `git commit - m` followed by a short message to commit the changes. 158 | 159 | `$ git commit -m "Initial commit"` 160 | 161 | - Tip: Try and make your messages short but meaningful. 162 | - Tip: It is possible, and sometimes encouraged, to add multiple files before making a single commit that encompasses all the changes to those files. 163 | 164 | ### 3. git push 165 | 166 | After commiting the changes, push the changes from your local machine to the remote repository. 167 | 168 | - In Terminal, use `git push origin` followed by the name of the branch you are pushing. 169 | 170 | `$ git push origin master` 171 | 172 | ### Useful Git Commands 173 | 174 | There are many other useful Git commands to help you track the status of your files. 175 | 176 | `git status` allows you to check the status of your repo, including: 177 | - Which branch you are working on 178 | - Which files are tracked or untracked 179 | - Which files are modified 180 | 181 | `git diff` followed by the file name allows you to check the changes to the given file 182 | 183 | ## Additional Information 184 | 185 | ### .gitignore 186 | 187 | Sometimes there are sensitive (or irrelevant) files that you do not want tracked by Git (e.g., passwords). 188 | 189 | Git uses a hidden file called *.gitignore* to indicate which files or file types (e.g., *.pkl, *.ipynb_checkpoints) not to track. After adding file names to the *.gitignore* file, changes made to files that match those names will not be tracked. 190 | 191 | Example: 192 | 193 | - Create a file called "credentials.json" in the directory of your repository. 194 | - If you run `git status`, you should see "credentials.json" under the untracked files section. 195 | - Create a file called *.gitignore* if it does not exist. 196 | - Add the text "credentials.json" to the *.gitignore* file 197 | - Save and close the *.gitignore* file 198 | - If you run `git status`, "credentials.json" should no longer appear. 199 | 200 | It's good practice to add, commit, and push the *.gitignore* file to Github so that your collaborators can see (and add) which files are not being tracked in the repository. 201 | 202 | ### Create a GitHub Repository 203 | 204 | You can create a new repository through the Github webpage. 205 | 206 | - From your Github profile on the Github webpage, click on the link, Repositories, located next to Overview. 207 | - Click on the green button labeled "New" located on the right side of the page. 208 | - Create and add a name for your repository. 209 | - Select the option to "Initialize this repository with a README" 210 | - Add a .gitignore file by selecting an option from the dropdown menu. 211 | - Each option represents a default .gitignore file for the given option. 212 | - For example, the Python option will by default include *.ipynb_checkpoints 213 | 214 | To clone the repository to your local machine, follow the steps outlined earlier. 215 | 216 | ### Create a new branch 217 | 218 | One of the most useful features of Git is the ability to develop on multiple branches. 219 | 220 | To **create** a new branch on your local machine, use `git checkout -b` followed by the name of your new branch. 221 | `$ git checkout -b add_excitement` 222 | 223 | To **add** the new branch to your remote repository, use `git push origin` followed by the name of the branch. 224 | `$ git push origin add_excitement` 225 | 226 | Use the basic add, commit, and push commands (pointing to this new branch) to develop on this branch. 227 | 228 | To **merge** one branch into another, use `git checkout` followed by the branch you want to merge into and `git merge` followed by the branch you are merging into the first branch. 229 | 230 | $ git checkout master 231 | $ git merge add_excitement 232 | 233 | To **locally delete** the branch, use `git branch -d` followed by the branch name. 234 | 235 | To **remotely delete** the branch, use `git push origin --delete` followed by the branch name. 236 | 237 | $ git branch -d add_excitement # local delete 238 | $ git push origin --delete add_excitement # remote delte 239 | 240 | **WARNING:** Performing these delete commands will remove any changes you made to files tracked on these branches. Make sure you have merged any changes you wish to keep into live branches before deleting old branches. 241 | 242 | Use `git branch` to see which branch you are currently working on. `git status` also notes which branch you are currently on. 243 | 244 | $ git branch 245 | $ git status 246 | 247 | ### Pull Requests 248 | 249 | When developing on a team, you rarely merge branches locally (i.e., the process described above). 250 | 251 | Typically branches are merged using pull requests (which also includes code review). 252 | 253 | A pull request is basically a request to another member of your team to review your code. If they think it looks good, they can accept the pull request (or PR) and merge your branch into another one, such as master or a main feature branch. 254 | 255 | #### 1. Create a pull request 256 | 257 | Create a pull request by going to the webpage of the Github repository. 258 | 259 | - On the Github repository page, click on the "Pull requests" link next to "Code" and "Issues". 260 | - Select the green "New pull request" button on the right side of the page. 261 | - Use the left-most dropdown menu, "base:", to select the branch you want to merge into. 262 | - Use the second dropdown menu, "compare:", to select the branch that you want to merge. 263 | - Click the green "Create pull request" button to access the options to create the pull request. 264 | - Leave a comment if you want to elaborate on the reason for the pull request or provide an update on the changes you made to the branch. 265 | - Click on the gear button next to "Assignees" to assign someone to review and merge the pull request. This has to be someone who is a collaborator on the project. 266 | - Select the green "Create pull request" button to open the pull request. 267 | 268 | #### 2. Accept a pull request 269 | 270 | On the Github repository webpage, review the pull request, accept changes, and merge the branch. 271 | 272 | - To review the pull request, check the "Commits" and "Files changed" options to review the code. 273 | - Within "Files changed", it's possible to add comments to single lines of code by selecting the "+" symbols next to each line. You have the option of submitting single comments or adding them to a review. 274 | - It's possible (but not necessary) to submit a full review by selecting the green "Review changes" button. 275 | - If the changes look good to you, on the "Conversations" tab, select the green "Merge pull request" button. 276 | - Select the green "Confirm merge" button to complete the merge. Add a comment at this stage if you would like to comment on the merge. 277 | 278 | #### 3. Delete the merged branch remotely 279 | 280 | After merging the branch, it's good practice to delete the working branch to declutter the repository. 281 | 282 | - On the pull request webpage, select the grey button called "Delete branch" to delete the merged branch remotely. 283 | 284 | #### 4. Delete the merged branch locally 285 | 286 | Before deleting the local merged branch, pull the changes into the base branch, then delete the local branch 287 | 288 | - In Terminal, switch to the base branch using `git checkout` followed by the name of the base branch. 289 | - Pull the merged changes using `git pull origin` followed by the name of the base branch. 290 | - Delete the merged branch using `git branch -d` followed by the name of the merged branch. 291 | ``` 292 | $ git checkout master 293 | $ git pull origin master 294 | $ git branch -d add_excitement 295 | ``` 296 | 297 | **WARNING:** Remember that when you delete a branch, you delete any of the changes that were tracked on it. Double check that your changes were merged into a live branch before deleting the branch. 298 | 299 | ## Best Practices 300 | 301 | ### When should I commit? 302 | Ideally you commit “working” code, so that you can return to a working state if necessary. Also, each commit should have one logical task that can be summarized in one phrase. 303 | 304 | ### When should I push? 305 | Always right after you commit. Why wouldn’t you want to have an immediate back up? 306 | 307 | ### Do I have to have commit messages? 308 | You at least need a descriptive title. This is an important part of code documentation (especially in a multi-developer environment). 309 | 310 | *Thank you to Mike Grinolds for his slides and GitHub tutorial!* 311 | --------------------------------------------------------------------------------