0.1.3 • Published 8 months ago
react-native-git v0.1.3
react-native-git
react-native-git is a React Native adapter for Git version control, built with JGit for Android. It allows you to perform basic Git operations via Typescript API.
Methods
Initialize a Repository
Parameters
- directoryPath: Directory name where the Git repository should be initialized.
const initRepo = async (directoryPath) => {
const gitDirectory = `${RNFS.DocumentDirectoryPath}/${directoryPath}`;
await RNFS.mkdir(gitDirectory);
const result = await git.initRepository(gitDirectory);
console.log(`Initialized Git repo at: ${gitDirectory}`, result);
};
Clone a Repository
Parameters:
- remoteUrl: URL of the remote repository to clone.
- localPath: Local directory where the repository will be cloned.
const cloneRepo = async (remoteUrl, localPath) => {
await git.cloneRepository(remoteUrl, localPath);
console.log(`Cloned repository from: ${remoteUrl} to ${localPath}`);
};
Commit Changes
Parameters:
- repoPath: Path to the local Git repository.
- message: Commit message to describe the changes.
- authorName: Name of the author committing the changes.
- authorEmail: Email of the author committing the changes.
const pushRepo = async (repoPath, remote = 'origin', branch = 'main', username, password) => {
await git.push(repoPath, remote, branch, username, password);
console.log(`Pushed changes to remote: ${remote} branch: ${branch}`);
};
Push Changes
Parameters:
- repoPath: Path to the local Git repository.
- remote: Remote repository name (default is origin).
- branch: Branch name to push (default is main).
- username: Username for authentication (optional).
- password: Password for authentication (optional).
const pushRepo = async (repoPath, remote = 'origin', branch = 'main', username, password) => {
await git.push(repoPath, remote, branch, username, password);
console.log(`Pushed changes to remote: ${remote} branch: ${branch}`);
};
Pull Changes
Parameters:
- repoPath: Path to the local Git repository.
- username: Username for authentication (optional).
- password: Password for authentication (optional).
const pullRepo = async (repoPath, username, password) => {
await git.pull(repoPath, username, password);
console.log('Pulled changes from the remote repository');
};
List Branches
Parameters:
- repoPath: Path to the local Git repository.
const listBranches = async (repoPath) => {
const branches = await git.getBranches(repoPath);
console.log('Available branches:', branches);
};
Checkout a Branch
Parameters:
- repoPath: Path to the local Git repository.
- branchName: Name of the branch to checkout.
const checkoutBranch = async (repoPath, branchName) => {
await git.checkoutBranch(repoPath, branchName);
console.log(`Checked out branch: ${branchName}`);
};