Spartronics4915
  • Introduction
  • Version Control and Git
    • Introducing Git and GitHub
    • Git Fundamentals
    • Next Level Git
    • Git Flow
    • FAQ: git, vi, bash shell
    • A Simple Tutorial
  • An Introduction to Java
    • Lesson 1: Introductory Syntax
    • Lesson 2: Variables and Datatypes
    • Lesson 3: Method Calls
    • Lesson 4: The If Statement
    • Lesson 5: Method Definitions
    • Lesson 6: Classes
    • Lesson 7: Inheritance
    • Helpful Programming Resources
  • Programming a Robot
    • Pre-Lesson: What is a Robot?
    • Setting up your Development Environment
    • Lesson 1: Motors and the Interative Robot
    • Lesson 2: What is a Subsystem?
    • Lesson 3: What are Commands?
    • Lesson 4: What are Command Groups?
    • Lesson 5: Scheduling Commands
  • Data Analysis
  • Arduino and Bling Development
    • Setup Arduino IDE
    • Starting with Bling
    • Spartronics Clock with NeoMatrix
    • Related Tutorials and Resources
Powered by GitBook
On this page
  • Common bash shell
  • Common vi commands
  • Common Git commands
  • How do I revert previous commit?
  • What is "non-fast-forward"?

Was this helpful?

  1. Version Control and Git

FAQ: git, vi, bash shell

PreviousGit FlowNextA Simple Tutorial

Last updated 4 years ago

Was this helpful?

Anything that relates to git or git related tools such as vi, or unix commands.

Common bash shell

# print working directory
$ pwd

# list contents of current directory
$ ls
# list contents of <dir>
$ ls <dir>
# list all/hidden files
$ ls -a

# take me to my home directory
$ cd
# change directory to <dir name>
$ cd <dir>
# change to directory above
$ cd ..

# print file to your screen
$ cat <filename>

# make directory
$ mkdir <dir_name>

# delete a file
$ rm <filename>

# recursively delete a directory -- BE VERY CAREFUL WITH THIS COMMAND!!
$ rm -rf <directory-name>

# copy a file from its current directory to another directory location
$ cp <filename> <directory-location>

# move a file from current directory to another directory location
$ mv <filename> <directory-location>
# rename a file in current directory -- applies to filename or directory name
$ mv <oldname> <newname>
# move & rename a file from current directory to directory above
$ mv <filename> ../<new-filename>

# open up an in-terminal text editor (note the shortcuts along the bottom)
$ nano
# edit a file
$ nano <filename>

Common vi commands

Git's default fallback editor is vi, a terminal text editor, similar to nano, but with a higher learning curve and more functionality.

It's important to know that vi has two modes: insertion and command. When you first start vi, editor is in command mode. "i" puts the editor in insertation mode, where you can type without triggering commands -- ESC returns the editor into command mode.

Common commands (in command mode):

# quit w/o saving -- <shift><:>
:q!
# save & quit
:wq
# change to insert mode
i
# delete word
dw

Common Git commands

# sets the name attached to commits - this should be your full name
git config --global user.name "name"

# sets the email attached to commits - should be the email used for GitHub
git config --global user.email "email"

# makes a new local repository with the specified name
git init <projectname>

# downloads a repository in the current directory
git clone <url>.git

# stages all modified files for commit
git add .

# commits all staged changes with a commit message
git commit -m "Commit message"

# pushes all commited changes to the origin repository
git push origin master

# pulls all changes from the latest version of the code
git pull upstream master

# fetches the latest commits without merging them
git fetch <repository> <branch>

# gets rid of ALL your changes and resets the repository to upstream - use with EXTREME CAUTION
git reset --hard upstream/master

How do I revert previous commit?

Sometimes you mess up, and don't realize it until after committing your changes.

Git makes it easy to revert your changes with use of the git reset command. Git reset lets you revert to a previous commit hash, which you have to find first with git log.

What is "non-fast-forward"?

Refer to various reference cards, such as .

We gave out a "Git Cheatsheet" at the beginning of the year that is very helpful. An online version can be found

Read more about git reset in

When your local repo is behind the repo you are pushing to you will see an error non-fast-forward updates were rejected. That means you need to retrieve the changes before you can push your changes. Read more about

this one
here.
git fundamentals.
git pull vs git fetch and git merge.
Frequently Asked Questions
Common bash shell
Common vi commands
Common Git commands
How do I revert previous commit?
What is "non-fast-forward"?