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