SkillAgentSearch skills...

G2

g2 - the friendly git command line client

Install / Use

/learn @orefalo/G2
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

[![Build Status][travis-badge]][travis-link] [![Slack Room][slack-badge]][slack-link]

image

Introduction

I see it every day, beginners have a hard time picking up git. Aside from the DSCM concepts, the command line is not easy: it is aimed at people who know git.. advanced nerds, not beginners.

This project is an attempt to make the git command line a friendly place: it eases the learning process by providing guidance and high level commands.

Benefits

  • g2 saves time by providing high level commands.
  • g2 is generally safer than git as it prompts before destructive actions.
  • g2 helps setup git: sshkeys, username, email and tools.
  • g2 provides two letter acronyms for most commands.
  • g2 eases the merge process by introducing three new verbs:sync, abort and continue.
  • g2 provides a reduced set of commands which give guidance on what to do next.
  • g2 enhances command line experience auto-completion.
  • g2 warns when a branch history was changed on the server (forced pushed).
  • g2 checks the freshness of the branch prior to merging and warns accordingly.
  • g2 enforces a clean linear history by introducing new commands.
  • g2 requires a clean state before rebasing, checking out, branching or merging.
  • g2 provides guidance when it cannot perform an operation.
  • g2 brings a number of friendly commands such as : panic, track, freeze, wip.
  • g2 eases branch creation.
  • g2 is just easier at undoing things, see the undo command

What G2 is not

  • A replacement for git. Rather, g2 is a layer on top of git
  • A magic way to learn GIT. It will only help by providing guidance.

Installation

** PRE-REQUISITES**:

  • g2 is a layer on top of git, If you are doing a manual install, a recent version of git must be pre-installed.
  • Please backup your favorite ~/.gitconfig as g2 with recreate it from scratch.
  • G2 runs bash and fishshell.

#MacOS/Linux

Only the fishshell version is maintained. With fisher v3 previously installed, run

$ fisher install orefalo/g2

How to use

The project overrides the g and git commands. Taken without parameters it displays the following output.

$ g
G2 Usage:
	abort - aborts any rebase/merge
	am <?-f> - amends last commit with staging area
	br <?-D> <?-M> <?branch> - list or create branches
	bs - bisect, aka bug finder
	co <branch> - switches branch (either local/remote)
	continue - resumes a conflict resolution
	cp <commit> - cherry-pick
	ci <?params...> - commit
	clone <url> - clone a remote repository
	df/dt <?params...> <file> - compares files
	fetch - gets changes sitting on the server
	freeze/unfreeze <?-m comment> <?file> - freeze/unfreeze files
	gc - garbage collects: run fsck & gc
	gp - grep
	gui - launches the GUI
	ig <file> - adds to gitignore & removes from source control
	init <folder> - init a repository
	key <?-gen> - displays/generates your ssh public key
	mg <?params...> <branch> - merge
	mt <?params...> - fixes conflicts by opening a visual merge-tool
	mv - move (rename) a file
	lg - displays commit log
	ls <?params...> - list files under source control
	panic - gets you back on HEAD, cleans all un-tracked files
	pull/push <?opts> <remote> <branch> - deals with other branches
	rb <?params...> <branch> or <upstream> - rebase
	rm <params...> - remove files
	rs <params...> - reset branch status
	rs upstream - resets branch to upstream state
	rt <?params...> - git remotes management
	rv <commit> - reverts commits
	server - starts a local git:// server on current repo
	setup - configures user, key, editor, tools
	sh <?-deep> - show commit contents
	sm <?params...> - sub-module
	ss <?params> - stash
	st <?params...> - status
	sync <?upstream> - syncs working branch: fetch, rebase & push
	tg - tag
	track <?upstream_branch> - shows/set tracking
	undo <file>|commit <hash>|merge - reverts changes
	wip/unwip - save/restore work in progress to branch

On top of providing two letters acronyms for most git commands, g2 has interesting features which enhance command line experience.

Completion

Thanks for Fish shell powerfull completion system, g2 comes with handy completion shortcuts.

type g <TAB> and enjoy a friendly list of commands to pick from. Completion also work on branch names, hashed, command names.

Setup

So here you go, you downloaded git for the first time and I bet you are stuck on the ssh key generation. git is so lame and user unfriendly.

alright, with g2 this is how it works:

  1. type g setup and answer the questions.
  2. that's it!

image

At anytime in the future, you may display your ssh public key with: g key. copy/paste it into github. You are done.

image

Should you need to regenerate the key pair, the process is equally user friendly: use g key -gen

image

Freeze, Unfreeze & Commit

I have some files I want to stage. Do I want git add ., git add -u, or git add -A? Which does what again? Confused. What about staging deletions?

g2 comes with simplicity in mind, rather the using some of the commands above, g2 introduces freeze and unfreeze.

image

Without arguments, g freeze literally freezes the state of the workspace into the staging area. It's convenient, one command to stage all the changes: additions and deletions. If I need to point the file to stage, I can use g freeze <path>.

Once changes are frozen, they can be committed with: g ci -m "commit description" There is also a handy one way command g freeze -m "msg", that skips the staging area and commits directly.

Ooops, I staged a change that I do not want to commit: I would then use g unfreeze <path> to get the file(s) out of the way.

Try the CheatSheet it helps visualize what commands do.

Undoing changes

Since we introduced unfreeze in the previous section, let's cover undoing: Standard git commands are very confusing when it comes to undoing things. It requires using the reset command which has a bunch of strange parameters that make writes to the git index. In fact, in order to undo changes properly, the reset command requires the user to have a clear understanding of the guts of the git index. This should not be the case for a common command, like undo.

So here comes g2 with the following undo scenarios:

  • g undo commit - undo the last commit, put changes back into the staging area.
  • g undo merge - reverts all commits up to the state before the last merge.
  • g undo myfile.txt - reverts any changes made to myfile.txt.

Reviewing the History

Working with beginners, I found that an easy way to keep them focused is to provide visuals. Now this is not the github network graph, but it's close enough to get them focused. Type g lg and enjoy the enhanced colorized commit log output.

image

Learn to read that tree, it's important: it holds the commit history for the current branch.

Panic!

It happened to all of us. You try a new command (like a rebase) and things don't work as expected: git complains on every commit attempt, the branch shows detached and some weird hex numbers show all around the place. Suddenly, you feel the urgency to hunt an expert advise: you start hunting the closest git-master: bad luck he's not around! In fact there is no-one to help you! "Damn it! I wish I never run that command!", you start pulling your hairs and screaming "CVS was so much bettttttter!"

Keep calm, you are panicking... and we built a command especially for you: g panic!

Use panic when you feel like getting help from your git master. The command will attempt to put you back on track: it checks out the last known good state (HEAD) and removes all files not under source control, leaving a clean workspace to resume from. It's the easiest way to get you back on track and ready to work. No more cold sweats, plus your git-master can rest. ;-)

Branching

Displaying the list of branches is achieved with the branch command: g br. Note how it provides details not only about the local and remote branches, but also about the state of these branches when compared to the status on the server.

$ g br
  gh-pages
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/gh-pages
  remotes/origin/master
---
gh-pages (ahead 0) | (behind 0) origin/gh-pages
master (ahead 0) | (behind 0) origin/master

Given a parameter, the command creates a new branch. g2 walks you though the steps that will typically take git 3 to 4 commands.

image

Use checkout g co NEW_branch to switch to that branch.

$ g br
  NEW_branch
  gh-pages
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/gh-pages
  remotes/origin/master
---
gh-pages (ahead 0) | (behind 0) origin/gh-pages
master (ahead 0) | (behind 0) origin/master
$ g co NEW_branch 
Switched to branch 'NEW_branch'
$ 

If you are familiar with git, this is no rocket science. There is however a hidden gem which might save you headaches going forward: g2 is extremely strict when it comes to switching branches: it only works from a stable state.

By stable state I mean: no modified files, no staged files. Should you have any changes, g2 will complain with the following message:

fatal: some files were changed on this branch, either commit <ci>, <wip> or <panic>.

Merging,continue & abort

g2 enforces a simpler merge flow by introducing commands abort & continue.

image

So what commands can get you into **mer

View on GitHub
GitHub Stars146
CategoryDevelopment
Updated2mo ago
Forks6

Languages

Shell

Security Score

95/100

Audited on Jan 22, 2026

No findings