Skip to content

Latest commit

 

History

History
83 lines (58 loc) · 3.45 KB

02-1-P-Git-Basics.adoc

File metadata and controls

83 lines (58 loc) · 3.45 KB

Git and GitHub

Installing Git

Install the Git version control system (VCS) from https://git-scm.com/downloads.

Creating a remote git repository on GitHub

  1. Go to https://github.com/new

  2. Set test as the name of the repository

  3. Check the checkbox Initialize this repository with a README

  4. Click on create repository

Cloning to a local repository

  1. Open up a terminal (Git bash on Windows).

  2. Navigate to the designated target directory (it is typical to use the git folder within the home directory for storing Git repositories, e.g., cd /home/username/git).

  3. Using a Git client, clone this newly created test repository to your computer. First, get the repository URL (use HTTPS for now).
    Repository URL
    Then, issue git clone https://url/of/the/repository.git
    You should get an output similar to this:
    Cloning a repository

  4. Verify the contents of the working copy of the repository by ls -la ./test. The .git folder holds version information and history for the repository, while the README.md is an auto-generated text file by GitHub.

Git basics

  1. Open up a terminal and configure username and email address. These are needed to identify the author of the different changes.
    Configuring username Configuring email
    Glossary — Part 1:

    • Git is your version control software

    • GitHub hosts your repositories

    • A repository is a collection of files and their history

    • A commit is a saved state of the repository

  2. Enter the working directory, then check the history by issuing git log. Example output:
    Example output for git log

  3. Adding and commiting a file: use the git add and git commit commands.
    git commit1 git commit2 git commit3
    The effect of these commands are explained on the figure below:
    git commit explained
    Glossary — Part 2:

    • Working Directory: files being worked on right now

    • Staging area: files ready to be committed

    • Repository: A collection of commits

  4. Checking current status is done with git status.
    git status

  5. Staging and unstaging files: use git add to add and git reset to remove files from the staging area.
    git add git status add git reset

    Caution
    Only staged files will be included in the next commit.
  6. To display detailed changes in unstaged files use git diff, while use git diff --staged to show changes within files staged for commit.
    git diff

  7. Reverting to a previous version is done using git checkout.
    git checkout

  8. The commands git pull (or the git fetch + git rebase combination) and git push are used to synchronize local and remote repositories.
    git remote

Browsing commit history on GitHub

  1. You can browse pushed commits in the remote repository online using GitHub. You can select the commits menu for a repository.
    commits menu
    To get a link for a specific commit, click on the button with the first few characters of the hash of the commit.
    commits select

The source for most of the images in the Git documentation: https://github.com/shabbir-hussain/ecse321tutorials/blob/master/01-githubTutorial1.pptx