Git/OpenWest 2016 Git Basics

From Omnia
< Git
Jump to navigation Jump to search

Presentation

Presentation:

https://www.openwest.org/schedule/#talk-190

Slides:

https://drive.google.com/open?id=1DUYry3lm66y_be_eerQblcmr27HI31FWnOxaUcnQSJY

Presenter:

Author: Mike Straw <straw@ohio.edu>

Description:

"Git (https://git-scm.com/) is an open source distributed version control system that can and does help manage everything from the smallest to the largest development environments. In this tutorial, we’ll explore the basics of using Git, and get our hands dirty with a small development environment using command-line, GUI, and web-based interfaces and look at some tools that can make Git even easier."

Git

https://git-scm.com/

VCS

Version Control System

types:

  • Local (eg. Word Track Changes)
  • Centralized (eg. Subversion)
  • Decentralized (eg. Git, Mercurial)

Git tracks changes, not versions, called "change sets"

Three tree architecture:

  • working
  • staging (git add)
  • repository (git commit)

Configuration

Config:

  • system (--system) # /etc/gitconfig
    • git config --system -l
  • user (--global) # ~/.gitconfig
    • git config --global -l
  • file (--file) [file] # specify config
    • git config --file .git/config -l
  • project --file .git/config
    • git config --file .git/config -l
  • all
    • git config -l

Config:

git config --global user.name 'Kenneth Burgener'
git config --global user.email 'kenneth@oeey.com'
git config --global core.editor /usr/bin/vim    # set editor to vim
git config --global core.editor `which vim`    # set editor to vim
git config --global color.ui true    # use color
git config --global -l    # list user configurations
git config --system -l    # list system configurations
git config --file .git/config -l    # list project configurations
git config -l    # list all configurations

Help

Help:

git help
git help init
git help log

Basics

Verison:

git --version


First Project:

mkdir gittest
cd gittest
git init
ls .git

Status:

git status

Stage file:

git add file.txt
# stage all files below current directory:
git add .

Stage file example:

git status
touch file1.txt
git add file1.txt
git status

Commit:

git commit -m 'my first commit'
git commit   # will ask for message in editor

Log:

git log
git log -n 1
git log -1
git log <commit>
git log <commit>..<commit>
git log --grep="first"
git log --since=”

Hashes:

  • Codes on commit and log are SHA-1 encrypted hashes
  • Based on exact contents of data - will change if tampered with
  • Can refer to them by the first # of chars to make it unique (usually 8-10)

Upstaging a file:

echo "changes" >> file1.txt
git checkout file1.txt

Stash

git stash
git pop

Tags

Tags:

git tag 1.0    # tag current code as 1.0
git tag    # shows list of tags
git tag -l    # shows list of tags
cat .git/refs/tags/1.0    # show tag 1.0 hash
git show 1.0    # show tag change set
git tag -a v1.2 9fceb02    # create a tag 'v1.2' at hash '9fceb02'
git push origin v1.2    # push tag to remote (does not happen by default)
git push origin --tags    # show remote tags
git checkout v1.2    # checkout changeset at tag v1.2
git checkout -b version12 v1.2    # checkout changeset at tag v1.2 as new branch

Reset

Reset file back to last commit:

git checkout -- file1.txt
git checkout -- .

Reset staged change:

git reset HEAD file1.txt

Removing a file

Ugly way:

rm file1.txt
git add file1.txt

Cleaner way:

git rm file1.txt

Amending Commit Message

Change last commit message:

commit --amend -m 'new message'

Diff

git diff
git diff <commit>
git diff <commit> <another commit>

Branching

Create a branch: (but not switch to it)

git branch <branch name>

Switch to an existing branch:

git checkout <branch name>

Create and switch to branch all in one:

git checkout -b <branch name>

Switch to an existing branch:

git checkout <branch name>

List branches:

git branch

Merge other branch into current branch:

git merge <other branch>
git checkout master
git merge mybranch   # merge mybranch into master

Rename a branch:

git branch -m <old name> <new name>

Delete a fully merged branch:

git branch -d <branch name>

Delete a branch: (with prejudice)

git branch -D <branch name>

Merging

Merge other branch into current branch:

git merge <other branch>
git checkout master
git merge mybranch   # merge mybranch into master

Complete merge:

# edit conflicted files
git add <conflicted_file>
git commit -m 'merged files'

Abort current merge attempt:

git merge --abort

This doesn't seem to work, but this does:

git checkout master -f

Remote Repositories

git clone

List branches, including remote:

git branch -a

Checkout remote branch:

git checkout -b <local branch> <remote branch>

Get all remote branches (from clean directory):

git clone --mirror <origin url> .git
git config --bool core.bare false
git reset --hard

Example:

git clone ssh://openwest@openwest.thestraws.net/home/openwest/git_demo  # password:4Git2016$tuff

Update from remote:

git fetch
git pull

Push changes:

git push

Push branch:

git push -u origin <branch_name>

Push all branches:

git push --all -u

Pull all branch

git pull --all

github

https://github.com

Can treat like a remote repository

e.g.: git clone https://github.com/scottw/dvcsh

Or visit https://github.com/scottw/dvcsh

github guide: hello world

https://guides.github.com/activities/hello-world/

Other Interfaces

GUIs

Web based

dig deeper

Pro Git: https://git-scm.com/book (also in your cloned project)

Git Completion: https://git-scm.com/book/en/v2/Git-in-Other-Environments-Git-in-Bash

GitHub: https://help.github.com/