Skip to content
Alfred edited this page Nov 13, 2020 · 11 revisions

Introduction to git

git is a Version Control System

  • A Version Control System is a software that tracks the file changes of all contributors within a project.
  • Originally developed to assist collaborative open source software development by Linus Torvalds (Initiator of Linux development)
  • The user chooses which files are tracked and which file changes are recorded.
  • All tracked files of a project are stored in a git repository ("repo").

git tracks file changes through commits

git status shows the current state of the repository

  $ git status

A commit records file changes within the repository

Adding files to the staging area, which will be included in the next commit.

$ git add ham.py
$ git add spam.txt

Creating the commit containing the files in the staging area:

$ git commit -m "edited ham.py, created spam.txt"

git needs to know who is creating the commit

Registering your user name and email:

$ git config --global user.name "Alfred Hettner"
$ git config --global user.email "hettner.alfred@gmail.com"

Note: This has to be done only once. It does not have to be your GitHub user name or email.

git log shows all commits of this repository

$ git log

Note: You can exit the log by typing "q", if you use the default command line editor vim.

Synchronizing your local commits with a central git repository

###Connecting a local repository to a central repository

Option 1: Clone the repository to your computer:

$ git clone https://github.com/geoscripting/preparatory-assignment-hettner

Option 2: Create a local repository and connect it to a central repository:

$ git init
$ git remote add origin https://github.com/hettner/my_empty_repo.git

Practical: git clone and add/commit/push

Below you find two videos showing you how to clone a repository and how to create and push commits to GitHub. Note that the files and the URLs in the video will be different from yours. I've added the commands that you should use according to the first assignment above the videos. In the video the Git Bash is used instead of the normal Windows command prompt.

In order to use git you need to have a GitHub Account and git must be installed on your computer.

1. Cloning the repository to your computer

In order to work on the files in the repository and to add new ones, you need to clone the repository to your computer using the following command.

Note: Replace the user name hettner with your GitHub user name.

$ git clone https://github.com/hettner/A1_TopographicWetnessIndex

Click on the image below to watch the video tutorial.

git_clone

2. Synchronizing your changes with GitHub

When you create or edit files, you can track these changes and synchronise them with the remote repository on GitHub using the following git commands.

  $ git add answer_question_1.txt
  $ git commit -m "added answer_question_1.txt"
  $ git push origin main

Click on the image below to watch the video tutorial.

git_commit

Resources

The Software Carpentry provides a good git tutorial <http://swcarpentry.github.io/git-novice/>_.