Learning Git

What you will learn

  • git concepts
    • git rebase vs merge
  • git commands
  • running git on server (simple vs gitlab)

What? Git is a free version control system created by Linus Torvalds in 2005. Used widely in IT industry.  Replaced older version control systems like Subversion, CVS.

Git concepts


Git rebase vs merge


Useful git commands

Git alias

- show alias
git config --get-regexp alias
git config --list | grep alias

- set username / email
git config --global user.name "your name"
git config --global user.email "your email"

- set aliases
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.purr pull -r
git config --global alias.l !git --no-pager lg -10
git config --global alias.spurs '!git stash && git pull && git stash pop'
git config --global alias.lg 'log --pretty=format:"%C(auto)%h - [%an], %d %ar : %C(cyan)%s" --graph'
git config --global core.excludesfile ~/.gitignore_global

Git pull local commit from 1 machine to another

- 1. Git pull on both machines to make sure you're up to date
git pull <host>:`pwd`

Creating a branch for pull request.

Assumes that you have a local commit.

- Manual
- Check current branches
git branch
- create new branch &amp; pull local commit into it
git branch {branch}
- checkout branch
git co {branch}
- push branch to remote
git push -u origin {branch}

- Not sure what this does?
git push origin master:{branch}

- Automatic
git start-pull-request (script at work)
enter {branch}
git push

- When creating a pull request n master has merge conflicts
git co master
git pull -r
git co {branch}
git rebase master
- manually resolve conflicts (eg Intellij)
git rebase --continue
- (git st should show diff between local n remote). Don't git purr again, but just force push)
git push -f

Managing local branches

- Show remote repositories
git remote -v

- Fetch prune from remote to clean up local branches
git fetch -p
- Delete local branch
git branch -d {branch}
- Force delete local branch
git branch -D {branch}

- Merge branch into master (eg to run mci &amp; validate it still passes)
git co master
git merge {branch}

Running Git Server