Giter VIP home page Giter VIP logo

gp's Introduction

gp: Git pull, push, push new remote branch

Like the waves.

Originally written in 2021 as I realized I could make fish abbreviations or shell aliases for most git commands using two letters, e.g. "gl" for git log, but "gp" could feasibly be "git pull" or "git push" Henceforth, I wrote this tool to consolidate both actions into one short command to fit my pattern. "gp" is now either "git push" or "git pull" or a no-op, depending on your git tree and the remote's statuses

Usage

gp --help
gp: Pull, push, push new branch. Version 1.4.0

- If there are changes in the remote branch, pull
- If there are changes in the local branch, push
- If there is no remote branch, prompt to push a new branch.
  Skip prompt with gp -f
- If the branches have diverged, do nothing.
  Force push with gp -f

USAGE: gp [-f|-v|-h|--version]
    -f|--force   Do not prompt for verification when pushing new branch.
                 Force push when local and remote branches diverged.
    -v|--verbose Show more output.
    -h|--help    Show this message.
    --version    Show program version.

To pull, push, or push a new remote branch:

gp

As above, but force push if diverged and do not prompt to push a new remote branch:

gp --force
gp -f

Installation

Option 1:

  1. Download raw.githubusercontent.com/roguh/gp/main/gp.
  2. Make executable and move to your preferred binary location.
chmod +x gp
sudo cp gp /usr/bin/gp

Option 2:

git clone https://github.com/roguh/gp.git
cd gp
make install

OR

git clone https://github.com/roguh/gp.git
cd gp
make install-to-user

Unit Testing

Linux: Running tests for many shells at once

make unit-test-on-linux

To include stricter POSIX shells:

make unit-test-all-on-linux

Bash: Running tests for many shells at once

make unit-test-on-macos

Integration Testing

Testing is a semi-manual process. Make sure you have permission to push new branches to the remote repository.

If the test script fails, the tests have failed. Also read the output to determine if gp is behaving correctly.

Note the test-integration-all-shells.sh script runs the test-integration.sh script using the test shell itself.

Linux: Running tests for many shells at once

make test-on-linux

MacOS: Running tests for many shells at once

make test-on-macos

Running tests for stricter POSIX shells

make test-on-strict-posix-shells

Running tests one shell at a time

Run the following commands:

./tests/test-integration.sh sh
./tests/test-integration.sh dash
./tests/test-integration.sh bash
BASH_COMPAT=31 ./tests/test-integration.sh bash
./tests/test-integration.sh zsh

Test results

Linux

Tested using GNU coreutils 9.0 in these shells:

  • dash 0.5
  • bash 5.1
  • bash 5.1 in bash 3.1 compatibility mode BASH_COMPAT=31
  • zsh 5.8
  • yash 2.52
  • ksh version 2020.0.0

MacOS

Not tested on MacOS, yet. It should work fine.

Linting and Compatibility Check

Use shellcheck to check shellscripts.

make check

Why?

  • I wanted a convenient shortcut for git pull and git push. I recently created git aliases (and fish abbreviations), e.g. gl for git log, and I wanted to use gp for either git pull or git push depending on the state of the repo. This needed more complex code so I wrote this script and eventually moved it to its own repo.
  • To demonstrate how I would deploy code. Features:
    • Linting and other automated checks.
    • Thorough tests.
      • Integration tests and a way to run them on many different platforms.
      • Unit tests that run on many shells, even on Bash 2.03
    • Good documentation.
    • GitHub Actions for running tests and code checks.

gp's People

Contributors

felina0 avatar roguh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.