MVG

Minimum Viable Git

Here are nine Git commands that I think you should be familiar with for Minimum Viable Git usage.

git init    creates a new git repo
      
git add    add something to the staging area for a change
git commit    commits the staged change(s) to the repo
      
git restore    undoes a change that you've made and restores a prior version
      
git clone    clones a remote repo into a new local repo
git push    pushes changes from the local repo to a remote repo
git pull    pulls changes to the local repo from a remote repo
      
git status    show the current status of the local repo
      
git help    get more information about a command

There are a LOT more Git commands. But I don't think they necessary for Minimum Viable Git usage.

git init

git init

git init creates a new git repo

This is only done once in a repo's lifetime.

git init [directory]

The [directory] is optional and defaults to the current directory [.].

A LOT of people use the following sequence of commands:

mkdir new-git-repo
cd new-git-repo
git init

I am lazy and I prefer to do the following

git init new-git-repo

git add

git add

git add adds something to the staging area for a change

git add notes.txt

To add the current directory [.] do the following:

git add .

You can think of the staging area like a place that you gather things as you prepare to create a commit.

git commit

git commit

git commit commits the staged change(s) to the repo

git commit takes the changes that you've staged and packages them up and applies them to the repo in a persistent manner.

git commit

Git will open the commit in your ${EDITOR} of choice where you can provide a commit message. Saving and exiting without error (RC=0) signals to git to do the commit. You can exit without saving (RC!=0) and git will abort the commit.

Optionally, you can specify the commit message on the command line.

git commit -m "adding meeting notes"

Optionally, you can view the contents of the commit with the --verbose (-v) option.

git commit -v 

git restore

git restore

git restore undoes a change that you've made and restores a prior version

Git has three primary areas things are placed:

  • working tree - the directory you do your work in
  • staging area - place things are staged before committing a change
  • repo objects - warehouse git stores things

To restore a file from the staging area to the working tree:

git restore notes.txt

To restore a file from the repo to the staging area, use this:

git restore --stage notes.txt 

git clone

git clone

git clone clones a remote repo into a new local repo

git clone  [directory]

The [directory] is optional and defaults to a name based on the source repo.

git clone https://git.sluug.org/example.git sluug-example-repo 

git push

git push

git push pushes changes from the local repo to a remote repo

git push [remote]

The [remote] is optional and defaults to where the clone is from.

git pull

git pull

git pull pulls changes to the local repo from a remote repo

git pull [remote]

The [remote] is optional and defaults to where it was cloned from.

git status

git status

git status shows the current status of the local repo

git status

git help

git help

git help is a convenient way to get more information.

git help [command]

The [command] is optional. Without the [command] git provides a very brief summary of the most common commands. With the [command] git shows the git-[command] manual page which includes extensive options and details for each [command].

These two commands are equivalent

git help <command>
man git-<command>

Q & A

  • Questions

    • Answers

      • Discussions

        • Minimum Viable Git, oh my!!!