github.com/moby/docker@v26.1.3+incompatible/docs/contributing/set-up-git.md (about) 1 ### Configure Git for contributing 2 3 Work through this page to configure Git and a repository you'll use throughout 4 the Contributor Guide. The work you do further in the guide, depends on the work 5 you do here. 6 7 ## Task 1. Fork and clone the Moby code 8 9 Before contributing, you first fork the Moby code repository. A fork copies 10 a repository at a particular point in time. GitHub tracks for you where a fork 11 originates. 12 13 As you make contributions, you change your fork's code. When you are ready, 14 you make a pull request back to the original Docker repository. If you aren't 15 familiar with this workflow, don't worry, this guide walks you through all the 16 steps. 17 18 To fork and clone Moby: 19 20 1. Open a browser and log into GitHub with your account. 21 22 2. Go to the <a href="https://github.com/moby/moby" 23 target="_blank">moby/moby repository</a>. 24 25 3. Click the "Fork" button in the upper right corner of the GitHub interface. 26 27  28 29 GitHub forks the repository to your GitHub account. The original 30 `moby/moby` repository becomes a new fork `YOUR_ACCOUNT/moby` under 31 your account. 32 33 4. Copy your fork's clone URL from GitHub. 34 35 GitHub allows you to use HTTPS or SSH protocols for clones. You can use the 36 `git` command line or clients like Subversion to clone a repository. 37 38  39 40 This guide assume you are using the HTTPS protocol and the `git` command 41 line. If you are comfortable with SSH and some other tool, feel free to use 42 that instead. You'll need to convert what you see in the guide to what is 43 appropriate to your tool. 44 45 5. Open a terminal window on your local host and change to your home directory. 46 47 ```bash 48 $ cd ~ 49 ``` 50 51 In Windows, you'll work in your Docker Quickstart Terminal window instead of 52 Powershell or a `cmd` window. 53 54 6. Create a `repos` directory. 55 56 ```bash 57 $ mkdir repos 58 ``` 59 60 7. Change into your `repos` directory. 61 62 ```bash 63 $ cd repos 64 ``` 65 66 8. Clone the fork to your local host into a repository called `moby-fork`. 67 68 ```bash 69 $ git clone https://github.com/YOUR_ACCOUNT/moby.git moby-fork 70 ``` 71 72 In the command above replace `YOUR_ACCOUNT` with your GitHub username. 73 Naming your local repo `moby-fork` should help make these instructions 74 easier to follow; experienced coders don't typically change the name. 75 76 9. Change directory into your new `moby-fork` directory. 77 78 ```bash 79 $ cd moby-fork 80 ``` 81 82 Take a moment to familiarize yourself with the repository's contents. List 83 the contents. 84 85 ## Task 2. Set your signature and an upstream remote 86 87 When you contribute to Docker, you must certify you agree with the 88 <a href="http://developercertificate.org/" target="_blank">Developer Certificate of Origin</a>. 89 You indicate your agreement by signing your `git` commits like this: 90 91 ``` 92 Signed-off-by: Pat Smith <pat.smith@email.com> 93 ``` 94 95 To create a signature, you configure your username and email address in Git. 96 You can set these globally or locally on just your `moby-fork` repository. 97 You must sign with your real name. You can sign your git commit automatically 98 with `git commit -s`. Moby does not accept anonymous contributions or contributions 99 through pseudonyms. 100 101 As you change code in your fork, you'll want to keep it in sync with the changes 102 others make in the `moby/moby` repository. To make syncing easier, you'll 103 also add a _remote_ called `upstream` that points to `moby/moby`. A remote 104 is just another project version hosted on the internet or network. 105 106 To configure your username, email, and add a remote: 107 108 1. Change to the root of your `moby-fork` repository. 109 110 ```bash 111 $ cd moby-fork 112 ``` 113 114 2. Set your `user.name` for the repository. 115 116 ```bash 117 $ git config --local user.name "FirstName LastName" 118 ``` 119 120 3. Set your `user.email` for the repository. 121 122 ```bash 123 $ git config --local user.email "emailname@mycompany.com" 124 ``` 125 126 4. Set your local repo to track changes upstream, on the `moby/moby` repository. 127 128 ```bash 129 $ git remote add upstream https://github.com/moby/moby.git 130 ``` 131 132 5. Check the result in your `git` configuration. 133 134 ```bash 135 $ git config --local -l 136 core.repositoryformatversion=0 137 core.filemode=true 138 core.bare=false 139 core.logallrefupdates=true 140 remote.origin.url=https://github.com/moxiegirl/moby.git 141 remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* 142 branch.master.remote=origin 143 branch.master.merge=refs/heads/master 144 user.name=Mary Anthony 145 user.email=mary@docker.com 146 remote.upstream.url=https://github.com/moby/moby.git 147 remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/* 148 ``` 149 150 To list just the remotes use: 151 152 ```bash 153 $ git remote -v 154 origin https://github.com/moxiegirl/moby.git (fetch) 155 origin https://github.com/moxiegirl/moby.git (push) 156 upstream https://github.com/moby/moby.git (fetch) 157 upstream https://github.com/moby/moby.git (push) 158 ``` 159 160 ## Task 3. Create and push a branch 161 162 As you change code in your fork, make your changes on a repository branch. 163 The branch name should reflect what you are working on. In this section, you 164 create a branch, make a change, and push it up to your fork. 165 166 This branch is just for testing your config for this guide. The changes are part 167 of a dry run, so the branch name will be dry-run-test. To create and push 168 the branch to your fork on GitHub: 169 170 1. Open a terminal and go to the root of your `moby-fork`. 171 172 ```bash 173 $ cd moby-fork 174 ``` 175 176 2. Create a `dry-run-test` branch. 177 178 ```bash 179 $ git checkout -b dry-run-test 180 ``` 181 182 This command creates the branch and switches the repository to it. 183 184 3. Verify you are in your new branch. 185 186 ```bash 187 $ git branch 188 * dry-run-test 189 master 190 ``` 191 192 The current branch has an * (asterisk) marker. So, these results show you 193 are on the right branch. 194 195 4. Create a `TEST.md` file in the repository's root. 196 197 ```bash 198 $ touch TEST.md 199 ``` 200 201 5. Edit the file and add your email and location. 202 203  204 205 You can use any text editor you are comfortable with. 206 207 6. Save and close the file. 208 209 7. Check the status of your branch. 210 211 ```bash 212 $ git status 213 On branch dry-run-test 214 Untracked files: 215 (use "git add <file>..." to include in what will be committed) 216 217 TEST.md 218 219 nothing added to commit but untracked files present (use "git add" to track) 220 ``` 221 222 You've only changed the one file. It is untracked so far by git. 223 224 8. Add your file. 225 226 ```bash 227 $ git add TEST.md 228 ``` 229 230 That is the only _staged_ file. Stage is fancy word for work that Git is 231 tracking. 232 233 9. Sign and commit your change. 234 235 ```bash 236 $ git commit -s -m "Making a dry run test." 237 [dry-run-test 6e728fb] Making a dry run test 238 1 file changed, 1 insertion(+) 239 create mode 100644 TEST.md 240 ``` 241 242 Commit messages should have a short summary sentence of no more than 50 243 characters. Optionally, you can also include a more detailed explanation 244 after the summary. Separate the summary from any explanation with an empty 245 line. 246 247 10. Push your changes to GitHub. 248 249 ```bash 250 $ git push --set-upstream origin dry-run-test 251 Username for 'https://github.com': moxiegirl 252 Password for 'https://moxiegirl@github.com': 253 ``` 254 255 Git prompts you for your GitHub username and password. Then, the command 256 returns a result. 257 258 ```bash 259 Counting objects: 13, done. 260 Compressing objects: 100% (2/2), done. 261 Writing objects: 100% (3/3), 320 bytes | 0 bytes/s, done. 262 Total 3 (delta 1), reused 0 (delta 0) 263 To https://github.com/moxiegirl/moby.git 264 * [new branch] dry-run-test -> dry-run-test 265 Branch dry-run-test set up to track remote branch dry-run-test from origin. 266 ``` 267 268 11. Open your browser to GitHub. 269 270 12. Navigate to your Moby fork. 271 272 13. Make sure the `dry-run-test` branch exists, that it has your commit, and the 273 commit is signed. 274 275  276 277 ## Where to go next 278 279 Congratulations, you have finished configuring both your local host environment 280 and Git for contributing. In the next section you'll [learn how to set up and 281 work in a Moby development container](set-up-dev-env.md).