Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ Main porcelain commands
git-log (Show commit logs.) <recipes/git-log>
git-show (Show various types of objects.) <recipes/git-show>
git-tag (Create, list, delete or verify a tag object signed with GPG.) <recipes/git-tag>
git clone (Clone with progress monitor) <recipes/git-clone-progress>
git clone --mirror (Clone with a mirroring configuration) <recipes/git-clone-mirror>
git clone username@hostname (Clone over ssh) <recipes/git-clone-ssh>
git-add / git-reset HEAD (Add file contents to the index / Unstage) <recipes/git-add-reset>
git commit (Make an initial commit, and a subsequent commit) <recipes/git-commit>

.. _git man page: https://www.kernel.org/pub/software/scm/git/docs/git.html
20 changes: 20 additions & 0 deletions docs/recipes/git-clone-progress.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
**********************************************************************
git-clone with progress monitor
**********************************************************************

Example for cloning a git repository with progress monitoring:

.. code-block:: bash

$ git clone https://github.com/libgit2/pygit2

.. code-block:: python

class MyRemoteCallbacks(pygit2.RemoteCallbacks):

def transfer_progress(self, stats):
print(f'{stats.indexed_objects}/{stats.total_objects}')

print("Cloning pygit2")
pygit2.clone_repository("https://github.com/libgit2/pygit2", "pygit2.git",
callbacks=MyRemoteCallbacks())
61 changes: 61 additions & 0 deletions docs/recipes/git-commit.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
**********************************************************************
git-commit
**********************************************************************

----------------------------------------------------------------------
Initial commit
----------------------------------------------------------------------

Add everything, and make an initial commit:

.. code-block:: bash

$ git add .
$ git commit -m "Initial commit"

.. code-block:: python

>>> index = repo.index
>>> index.add_all()
>>> index.write()
>>> ref = "HEAD"
>>> author = Signature('Alice Author', 'alice@authors.tld')
>>> committer = Signature('Cecil Committer', 'cecil@committers.tld')
>>> message = "Initial commit"
>>> tree = index.write_tree()
>>> parents = []
>>> repo.create_commit(ref, author, committer, message, tree, parents)


----------------------------------------------------------------------
Subsequent commit
----------------------------------------------------------------------

Once ``HEAD`` has a commit to point to, you can use ``repo.head.name`` as the
reference to be updated by the commit, and you should name parents:

.. code-block:: python

>>> ref = repo.head.name
>>> parents = [repo.head.target]

The rest is the same:

.. code-block:: python

>>> index = repo.index
>>> index.add_all()
>>> index.write()
>>> author = Signature('Alice Author', 'alice@authors.tld')
>>> committer = Signature('Cecil Committer', 'cecil@committers.tld')
>>> message = "Initial commit"
>>> tree = index.write_tree()
>>> repo.create_commit(ref, author, committer, message, tree, parents)

----------------------------------------------------------------------
References
----------------------------------------------------------------------

- git-commit_.

.. _git-commit: https://www.kernel.org/pub/software/scm/git/docs/git-commit.html