npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@push.rocks/smartgit

v3.1.1

Published

A smart wrapper for nodegit that simplifies Git operations in Node.js.

Downloads

229

Readme

@push.rocks/smartgit

smart wrapper for nodegit

Install

To install @push.rocks/smartgit, use the following command with npm:

npm install @push.rocks/smartgit --save

Or if you prefer using yarn:

yarn add @push.rocks/smartgit

Make sure you have node installed on your system to use this package.

Usage

This guide assumes familiarity with TypeScript and basic Git operations. The @push.rocks/smartgit module offers a sophisticated, promise-based interface to interact with Git repositories in a Node.js environment, abstracting over the isomorphic-git library and adding additional functionality.

Setting Up

First, you need to import Smartgit and other necessary classes from the package. This is also when you'd typically configure any additional settings or dependencies required by your project.

import { Smartgit } from '@push.rocks/smartgit';

// Initialize the Smartgit instance
const smartgit = new Smartgit();
await smartgit.init();

Creating, Cloning, and Opening Repositories

With Smartgit, you can easily manage local repositories by creating new ones, cloning existing repositories, or opening an already existing local repository.

Creating a New Repository

const pathToNewRepo = '/path/to/your/new/repo';
const newRepo = await smartgit.createRepoByInit(pathToNewRepo);

Cloning a Repository

const cloneUrl = 'https://github.com/yourusername/your-repo.git';
const pathToClone = '/path/to/clone/repo';
const clonedRepo = await smartgit.createRepoByClone(cloneUrl, pathToClone);

Opening an Existing Repository

const pathToExistingRepo = '/path/to/your/existing/repo';
const existingRepo = await smartgit.createRepoByOpen(pathToExistingRepo);

Working with Git Operations

Smartgit simplifies common Git operations, making it easy to execute commands like add, commit, push, and more programmatically.

Adding Changes

To stage changes, you can add all changes or specify particular files.

// Add all changes to staging
await existingRepo.addAll();

// Or specify particular files
await existingRepo.add(['file1.txt', 'path/to/file2.txt']);

Committing Changes

Once changes are staged, you can commit them.

await existingRepo.commit('Your commit message');

Pushing to a Remote

Before pushing, ensure a remote is set up correctly, then push your changes.

await existingRepo.ensureRemote('origin', 'https://github.com/yourusername/your-repo.git');
await existingRepo.pushBranchToRemote('main', 'origin');

Advanced Features

Smartgit also supports more advanced Git functionalities, such as dealing with branches, managing remotes, and checking repository status.

Listing Remotes

const remotes = await existingRepo.listRemotes();
console.log(remotes);

Working with Branches

Branch management such as creating new branches or checking out existing ones can be done through the underlying isomorphic-git functions, with Smartgit making the setup and usage straightforward.

Practical Tips

  • When dealing with asynchronous operations, especially in sequences that depend on the outcome of previous steps (e.g., staging, committing, and pushing), ensure proper error handling, either using .then().catch() chains or try/catch blocks with async/await.
  • For complex Git workflows, consider combining Smartgit's capabilities with other Node.js modules or scripts to automate and streamline your processes.

Conclusion

@push.rocks/smartgit provides a versatile and powerful toolkit for Git operations in Node.js applications. By abstracting the complexities of interacting with Git repositories, it enables developers to focus more on developing their logic and less on the intricacies of Git commands. Whether you're managing local repositories, automating deployment workflows, or integrating Git operations into your applications, Smartgit offers a comprehensive set of features to address your needs.

For further examples, contributions, and issues, please refer to the project's repository and consider contributing to or starring the project if you find it useful.

License and Legal Information

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at [email protected].

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.