| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ GitPython Documentation | |||
| 9 | 9 | :maxdepth: 2 | |
| 10 | 10 | ||
| 11 | 11 | intro | |
| 12 | + quickstart | ||
| 12 | 13 | tutorial | |
| 13 | 14 | reference | |
| 14 | 15 | roadmap | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,244 @@ | |||
| 1 | + .. _quickdoc_toplevel: | ||
| 2 | + | ||
| 3 | + .. highlight:: python | ||
| 4 | + | ||
| 5 | + .. _quickdoc-label: | ||
| 6 | + | ||
| 7 | + ============================== | ||
| 8 | + GitPython Quick Start Tutorial | ||
| 9 | + ============================== | ||
| 10 | + Welcome to the GitPython Quickstart Guide! Designed for developers seeking a practical and interactive learning experience, this concise resource offers step-by-step code snippets to swiftly initialize/clone repositories, perform essential Git operations, and explore GitPython's capabilities. Get ready to dive in, experiment, and unleash the power of GitPython in your projects! | ||
| 11 | + | ||
| 12 | + | ||
| 13 | + git.Repo | ||
| 14 | + ******** | ||
| 15 | + | ||
| 16 | + There are a few ways to create a :class:`git.Repo <git.repo.base.Repo>` object | ||
| 17 | + | ||
| 18 | + Initialize a new git Repo | ||
| 19 | + ######################### | ||
| 20 | + | ||
| 21 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 22 | + :language: python | ||
| 23 | + :dedent: 8 | ||
| 24 | + :start-after: # [1-test_init_repo_object] | ||
| 25 | + :end-before: # ![1-test_init_repo_object] | ||
| 26 | + | ||
| 27 | + Existing local git Repo | ||
| 28 | + ####################### | ||
| 29 | + | ||
| 30 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 31 | + :language: python | ||
| 32 | + :dedent: 8 | ||
| 33 | + :start-after: # [2-test_init_repo_object] | ||
| 34 | + :end-before: # ![2-test_init_repo_object] | ||
| 35 | + | ||
| 36 | + Clone from URL | ||
| 37 | + ############## | ||
| 38 | + | ||
| 39 | + For the rest of this tutorial we will use a clone from https://github.com/gitpython-developers/QuickStartTutorialFiles.git | ||
| 40 | + | ||
| 41 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 42 | + :language: python | ||
| 43 | + :dedent: 8 | ||
| 44 | + :start-after: # [1-test_cloned_repo_object] | ||
| 45 | + :end-before: # ![1-test_cloned_repo_object] | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + Trees & Blobs | ||
| 49 | + ************** | ||
| 50 | + | ||
| 51 | + Latest Commit Tree | ||
| 52 | + ################## | ||
| 53 | + | ||
| 54 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 55 | + :language: python | ||
| 56 | + :dedent: 8 | ||
| 57 | + :start-after: # [12-test_cloned_repo_object] | ||
| 58 | + :end-before: # ![12-test_cloned_repo_object] | ||
| 59 | + | ||
| 60 | + Any Commit Tree | ||
| 61 | + ############### | ||
| 62 | + | ||
| 63 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 64 | + :language: python | ||
| 65 | + :dedent: 8 | ||
| 66 | + :start-after: # [13-test_cloned_repo_object] | ||
| 67 | + :end-before: # ![13-test_cloned_repo_object] | ||
| 68 | + | ||
| 69 | + Display level 1 Contents | ||
| 70 | + ######################## | ||
| 71 | + | ||
| 72 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 73 | + :language: python | ||
| 74 | + :dedent: 8 | ||
| 75 | + :start-after: # [14-test_cloned_repo_object] | ||
| 76 | + :end-before: # ![14-test_cloned_repo_object] | ||
| 77 | + | ||
| 78 | + Recurse through the Tree | ||
| 79 | + ######################## | ||
| 80 | + | ||
| 81 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 82 | + :language: python | ||
| 83 | + :dedent: 8 | ||
| 84 | + :start-after: # [15-test_cloned_repo_object] | ||
| 85 | + :end-before: # ![15-test_cloned_repo_object] | ||
| 86 | + | ||
| 87 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 88 | + :language: python | ||
| 89 | + :dedent: 8 | ||
| 90 | + :start-after: # [16-test_cloned_repo_object] | ||
| 91 | + :end-before: # ![16-test_cloned_repo_object] | ||
| 92 | + | ||
| 93 | + | ||
| 94 | + | ||
| 95 | + | ||
| 96 | + Usage | ||
| 97 | + **************** | ||
| 98 | + | ||
| 99 | + Add file to staging area | ||
| 100 | + ######################## | ||
| 101 | + | ||
| 102 | + | ||
| 103 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 104 | + :language: python | ||
| 105 | + :dedent: 8 | ||
| 106 | + :start-after: # [2-test_cloned_repo_object] | ||
| 107 | + :end-before: # ![2-test_cloned_repo_object] | ||
| 108 | + | ||
| 109 | + Now lets add the updated file to git | ||
| 110 | + | ||
| 111 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 112 | + :language: python | ||
| 113 | + :dedent: 8 | ||
| 114 | + :start-after: # [3-test_cloned_repo_object] | ||
| 115 | + :end-before: # ![3-test_cloned_repo_object] | ||
| 116 | + | ||
| 117 | + Notice the add method requires a list as a parameter | ||
| 118 | + | ||
| 119 | + Warning: If you experience any trouble with this, try to invoke :class:`git <git.cmd.Git>` instead via repo.git.add(path) | ||
| 120 | + | ||
| 121 | + Commit | ||
| 122 | + ###### | ||
| 123 | + | ||
| 124 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 125 | + :language: python | ||
| 126 | + :dedent: 8 | ||
| 127 | + :start-after: # [4-test_cloned_repo_object] | ||
| 128 | + :end-before: # ![4-test_cloned_repo_object] | ||
| 129 | + | ||
| 130 | + List of commits associated with a file | ||
| 131 | + ####################################### | ||
| 132 | + | ||
| 133 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 134 | + :language: python | ||
| 135 | + :dedent: 8 | ||
| 136 | + :start-after: # [5-test_cloned_repo_object] | ||
| 137 | + :end-before: # ![5-test_cloned_repo_object] | ||
| 138 | + | ||
| 139 | + Notice this returns a generator object | ||
| 140 | + | ||
| 141 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 142 | + :language: python | ||
| 143 | + :dedent: 8 | ||
| 144 | + :start-after: # [6-test_cloned_repo_object] | ||
| 145 | + :end-before: # ![6-test_cloned_repo_object] | ||
| 146 | + | ||
| 147 | + returns list of :class:`Commit <git.objects.commit.Commit>` objects | ||
| 148 | + | ||
| 149 | + Printing text files | ||
| 150 | + #################### | ||
| 151 | + Lets print the latest version of `<local_dir>/dir1/file2.txt` | ||
| 152 | + | ||
| 153 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 154 | + :language: python | ||
| 155 | + :dedent: 8 | ||
| 156 | + :start-after: # [17-test_cloned_repo_object] | ||
| 157 | + :end-before: # ![17-test_cloned_repo_object] | ||
| 158 | + | ||
| 159 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 160 | + :language: python | ||
| 161 | + :dedent: 8 | ||
| 162 | + :start-after: # [18-test_cloned_repo_object] | ||
| 163 | + :end-before: # ![18-test_cloned_repo_object] | ||
| 164 | + | ||
| 165 | + Previous version of `<local_dir>/dir1/file2.txt` | ||
| 166 | + | ||
| 167 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 168 | + :language: python | ||
| 169 | + :dedent: 8 | ||
| 170 | + :start-after: # [18.1-test_cloned_repo_object] | ||
| 171 | + :end-before: # ![18.1-test_cloned_repo_object] | ||
| 172 | + | ||
| 173 | + Status | ||
| 174 | + ###### | ||
| 175 | + * Untracked files | ||
| 176 | + | ||
| 177 | + Lets create a new file | ||
| 178 | + | ||
| 179 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 180 | + :language: python | ||
| 181 | + :dedent: 8 | ||
| 182 | + :start-after: # [7-test_cloned_repo_object] | ||
| 183 | + :end-before: # ![7-test_cloned_repo_object] | ||
| 184 | + | ||
| 185 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 186 | + :language: python | ||
| 187 | + :dedent: 8 | ||
| 188 | + :start-after: # [8-test_cloned_repo_object] | ||
| 189 | + :end-before: # ![8-test_cloned_repo_object] | ||
| 190 | + | ||
| 191 | + * Modified files | ||
| 192 | + | ||
| 193 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 194 | + :language: python | ||
| 195 | + :dedent: 8 | ||
| 196 | + :start-after: # [9-test_cloned_repo_object] | ||
| 197 | + :end-before: # ![9-test_cloned_repo_object] | ||
| 198 | + | ||
| 199 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 200 | + :language: python | ||
| 201 | + :dedent: 8 | ||
| 202 | + :start-after: # [10-test_cloned_repo_object] | ||
| 203 | + :end-before: # ![10-test_cloned_repo_object] | ||
| 204 | + | ||
| 205 | + returns a list of :class:`Diff <git.diff.Diff>` objects | ||
| 206 | + | ||
| 207 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 208 | + :language: python | ||
| 209 | + :dedent: 8 | ||
| 210 | + :start-after: # [11-test_cloned_repo_object] | ||
| 211 | + :end-before: # ![11-test_cloned_repo_object] | ||
| 212 | + | ||
| 213 | + Diffs | ||
| 214 | + ###### | ||
| 215 | + | ||
| 216 | + Compare staging area to head commit | ||
| 217 | + | ||
| 218 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 219 | + :language: python | ||
| 220 | + :dedent: 8 | ||
| 221 | + :start-after: # [11.1-test_cloned_repo_object] | ||
| 222 | + :end-before: # ![11.1-test_cloned_repo_object] | ||
| 223 | + | ||
| 224 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 225 | + :language: python | ||
| 226 | + :dedent: 8 | ||
| 227 | + :start-after: # [11.2-test_cloned_repo_object] | ||
| 228 | + :end-before: # ![11.2-test_cloned_repo_object] | ||
| 229 | + | ||
| 230 | + Compare commit to commit | ||
| 231 | + | ||
| 232 | + .. literalinclude:: ../../test/test_quick_doc.py | ||
| 233 | + :language: python | ||
| 234 | + :dedent: 8 | ||
| 235 | + :start-after: # [11.3-test_cloned_repo_object] | ||
| 236 | + :end-before: # ![11.3-test_cloned_repo_object] | ||
| 237 | + | ||
| 238 | + | ||
| 239 | + More Resources | ||
| 240 | + **************** | ||
| 241 | + | ||
| 242 | + Remember, this is just the beginning! There's a lot more you can achieve with GitPython in your development workflow. | ||
| 243 | + To explore further possibilities and discover advanced features, check out the full :ref:`GitPython tutorial <tutorial_toplevel>` | ||
| 244 | + and the :ref:`API Reference <api_reference_toplevel>`. Happy coding! | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments