From e395ac90bf088ad6b5de7dadb6531a6e7f3f4f3f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 19 Jan 2015 18:53:40 +0100 Subject: Added tutorial about initializing a repository. Additionally, for this and future examples, there is a test_doc.py suite to contain all code mentioned in the docs. That way, we know if things stop working. Fixes #236 --- doc/source/tutorial.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'doc/source') diff --git a/doc/source/tutorial.rst b/doc/source/tutorial.rst index 3f45b70d..4921d07b 100644 --- a/doc/source/tutorial.rst +++ b/doc/source/tutorial.rst @@ -415,6 +415,22 @@ The previous approach would brutally overwrite the user's changes in the working repo.heads.master.checkout() # checkout the branch using git-checkout repo.heads.other_branch.checkout() +Initializing a repository +************************* + +In this example, we will initialize an empty repository, add an empty file to the index, and commit the change:: + + repo_dir = 'my-new-repo' + file_name = os.path.join(repo_dir, 'new-file') + + r = git.Repo.init(repo_dir) + # This function just creates an empty file ... + touch(file_name) + r.index.add([file_name]) + r.index.commit("initial commit") + +Please have a look at the individual methods as they usually support a vast amount of arguments to customize their behavior. + Using git directly ****************** In case you are missing functionality as it has not been wrapped, you may conveniently use the git command directly. It is owned by each repository instance:: -- cgit v1.2.1