Reasons For Using Git and GitLab/GitHub

You have been using git to submit your work to GitLab.

But that isn’t what git is really about.

git is a version control (VCS) system; these are also called revision control systems (RCS) or source code management systems (SCMS)).

What version control systems do for you:

Good Git Habits

To take advantage of these capabilities you need to develop some good practices:

Working With Git

If all goes well:

If you run into issues, you will need to use some more git tools.

The most common operations are well supported by RStudio or GitLab:

Other operations are easier, or only possible, using the command line:

git Operations with RStudio

You can perform git operations with:

  • The Tools > Version Control menu.

  • The Git tab.

Examples:

  • Make a change, longer commit message, push.

  • Review history, get old file versions.

  • Create folders, renaming files.

git Operations with GitLab

  • Review history, get old file versions.

  • Check out Blame tab.

Using Command Line git in a Shell/Terminal

Set Up a Reasonable Editor

Occasionally git will want to open an editor to let you enter a commit message.

The default editor it uses (usually vi or vim) is probably not useful.

You can register a more reasonable editor using

  git config --global core.editor <editor>

Replace <editor> with the name of a program that opens your editor when run from the command line with a text file argument.

  • On Linux you can use gedit or nano.

  • On Windows notepad should work.

  • On Mac OS you should be able to use nano.

Or use your favorite editor if you have one.

You only need to do this once on each system you use. The information you provide is included in a .gitconfig file in your home directory.

If you don’t do this you may end up with git using the vi or the vim editor, which is powerful but not intuitive if you haven’t used it.

  • If you end up in vi, type :q<return> to get out.

Common Commands

  • git clone <repository> [<directory>]
  • git status
  • git pull
  • git add <file1> <file2> ...
  • git commit or git commit -m "<message>"
  • git push

Other Commands

  • git log [<file>]
  • git blame <file>
  • git mv <oldname> <newname>
  • git show <REVHASH>:<filepath>

Examples

  • Log, blame
  • Create, rename
  • Change, longer commit message
    • If you end up in vi, type :q<return> to get out.

Conflicts

It you work on several computers, or collaborate with someone, you may need to resolve conflicts.

Reverting a Specific Commit

GitLab/GitHub features

GitLab and GitHub are social coding platforms.

In addition to providing a remote repository, they provide a number of facilities to aid in collaboration.

Two important facilities are:

Issues can be assigned to someone to deal with; assigning an issue will generate an email to the assignee.

Some Useful Resources