gitinit - Initialize empty Git repository - MATLAB (original) (raw)

Main Content

Initialize empty Git repository

Since R2023b

Syntax

Description

[repo](#mw%5F53601b05-6c27-4c87-a88b-d859360bfcee%5Fsep%5Fmw%5F986004a2-eb66-491b-9044-75c85face56b) = gitinit initializes an empty Git™ repository in the current folder and returns amatlab.git.GitRepository object. The gitinit function also creates .gitignore and .gitattributes files. The .gitattributes file contains the list of common binary files to register and protect from corruption. For more information, see Register Binary Files with Git.

example

[repo](#mw%5F53601b05-6c27-4c87-a88b-d859360bfcee%5Fsep%5Fmw%5F986004a2-eb66-491b-9044-75c85face56b) = gitinit([folder](#mw%5F53601b05-6c27-4c87-a88b-d859360bfcee%5Fsep%5Fmw%5Fe42db8e7-a6e4-4f00-bc1c-a193dccaab32)) initializes an empty Git repository in the specified folder and returns amatlab.git.GitRepository object.

example

[repo](#mw%5F53601b05-6c27-4c87-a88b-d859360bfcee%5Fsep%5Fmw%5F986004a2-eb66-491b-9044-75c85face56b) = gitinit(___,[Name=Value](#namevaluepairarguments)) specifies additional options as one or more name-value arguments.

example

Examples

collapse all

Initialize Git Repository in Current Folder

Create an empty repository in the current folder. After you create the repository, you can add and commit files to it.

repo =

GitRepository with properties:

 WorkingFolder: "C:\workSpace\newrepo"
     GitFolder: "C:\workSpace\newrepo\.git"
 CurrentBranch: [0×0 GitBranch]
    LastCommit: [0×0 GitCommit]
 ModifiedFiles: [0×1 string]
UntrackedFiles: [2×1 string]
        IsBare: 0
     IsShallow: 0
    IsDetached: 0
    IsWorktree: 0

Initialize Git Repository in Specified Folder

Create an empty repository in the specified folder. After you create the repository, you can add and commit files to it.

mkdir("newrepo"); repo = gitinit("newrepo")

repo =

GitRepository with properties:

 WorkingFolder: "C:\workSpace\newrepo"
     GitFolder: "C:\workSpace\newrepo\.git"
 CurrentBranch: [0×0 GitBranch]
    LastCommit: [0×0 GitCommit]
 ModifiedFiles: [0×1 string]
UntrackedFiles: [2×1 string]
        IsBare: 0
     IsShallow: 0
    IsDetached: 0
    IsWorktree: 0

Create Bare Repository in Current Folder

Create a bare repository in the current folder.

repo = gitinit(pwd,Bare=true)

repo =

GitRepository with properties:

 WorkingFolder: "C:\workSpace\newfolder2"
     GitFolder: "C:\workSpace\newfolder2\.git"
 CurrentBranch: [0×0 GitBranch]
    LastCommit: [0×0 GitCommit]
 ModifiedFiles: [0×1 string]
UntrackedFiles: [5×1 string]
        IsBare: 1
     IsShallow: 0
    IsDetached: 0
    IsWorktree: 0

Input Arguments

collapse all

folder — Path of folder

character vector | string scalar

Path of the folder in which the function initializes a repository, specified as a character vector or string scalar.

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: gitinit(pwd,Bare=true)

InitialBranch — Name of initial branch

string scalar | character vector

Name of the initial branch, specified as a string scalar or a character vector. If you do not specify this input, the function uses the value ofinit.defaultbranch in your global .gitconfig file. If init.defaultbranch is empty, thegitinit function names the initial branchmain.

To check the content of the global .giticonfig file, in MATLAB®, enter:

!git config --global --list

init.defaultbranch=trunk merge.mlAutoMerge.driver="C:/Program Files/MATLAB/R2023b/bin/win64/mlAutoMerge.bat" %O %A %B %A mergetool.mlMerge.cmd="C:/Program Files/MATLAB/R2023b/bin/win64/mlMerge.exe" BASEBASE BASELOCAL REMOTEREMOTE REMOTEMERGED difftool.mlDiff.cmd="C:/Program Files/MATLAB/R2023b/bin/win64/mlDiff.exe" LOCALLOCAL LOCALREMOTE credential.https://insidelabs-git.mathworks.com.provider=generic user.name=myname user.email=myname@mathworks.com core.longpaths=true

Example: "trunk"

Data Types: char | string

Bare — Option to create bare Git repository

false or 0 (default) | true or 1

Option to create a bare Git repository, specified as a numeric or logical 1 (true) or 0 (false).

A bare Git repository is commonly used as a remote repository where code is shared between members of the team. Bare Git repositories are not used for local development. You cannot commit to bare repositories, but you can pull and push changes.

Data Types: logical

Reinit — Option to reinitialize Git repository

false or 0 (default) | true or 1

Option to reinitialize a Git repository, specified as a numeric or logical 1 (true) or 0 (false).

Reinitializing a Git repository copies new templates to the .git folder and creates .gitignore and .gitattributes files if they do not exist.

Data Types: logical

Output Arguments

Version History

Introduced in R2023b