Introduction to Git

[for Perforce users]

Fabio Pitino

from git-scm.com:

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

<== Git

Perforce ==>

3 stages of Git

Files modified

Files staged

Files committed

Starting a project

cd ~/code
mkdir git-demo
cd git-demo
git init

# do your work
git add <file>
git commit -m "initial commit"

git remote add origin https://usr@stash.ges.symantec.com/scm/ccae/git-demo.git
git push -u origin master
cd ~/code
git clone https://usr@stash.ges.symantec.com/scm/ccae/git-demo.git 
cd git-demo

# do your work
git add <file>
git commit -m "my first commit"

git push -u origin master

If start without a Git repository:

If you already have a Git repository

A typical working day...

[demo]

add files
edit files
show diff (cached, unstaged)
stage
unstage
commit
push

Git's states

  • missing transition "checkout": Repository --> Workspace

Branching

add file1.txt
add file2.txt

commit file1.txt
commit file2.txt

git checkout -b fp-test_branch
edit file1.txt
commit file1.txt

git checkout master
edit file1.txt
commit file1.txt

# notice branch diverging when using 'git sla'

git checkout fp-test_branch
git push origin fp-test_branch

# create PR
# simulate code review

git checkout master # simulate somebody creating a conflict
git push

# show that PR cannot be merged
# Fix conflict on browser
# merge PR

git pull # on master

git branch -D fp-test_branch

.gitignore file

.bundle
/.env
/**/.DS_Store
/data/*
/log/*

/rails/.rake_tasks*
/rails/log/*
/rails/public/scan_logs/*
/rails/ssl/*
/rails/tmp/*
/config/nginx.conf

!/log/.keep
!/rails/log/.keep
!/rails/tmp/.keep

/tags
/udo mysql*

Git

  • distributed
    • can work offline
    • extremely fast
  • cheap copies
  • edit files directly
  • one directory as a workspace
  • 1-repo, 1-project
    • forces separate repos
  • series of added snapshots
  • full control over history
  • commit ID is a SHA-1
  • changes based on commits - no file revision #

Perforce

  • centralized
    • no offline work
    • as slow as the network
  • full copies
  • must check-out files before edit
  • multiple directories when working with branches
  • large repo w/ multiple projects
    • workspace configurations
  • sequence of deltas
  • no control over history
  • commit ID is a sequential number
  • changes base on files - concept of revision #
  • Git is extremely fast because you interact with local files 99% of the time.
  • Git is a mini and highly optimised filesystem
  • Only push/pull to/from remote repo when you want to share the work

Git

  • Team manages repository access control
  • ACL only for projects and repositories
  • UI tools: SourceTree, gitk
    • cmd line is very powerful
    • browser for remote branches only

Perforce

  • P4 admins manage repository access control
  • Fine grained ACL at any level from top level directory to file
  • UI tools: P4V

Switching from P4 to Git

  • Learning a new tool
    • learning curve is very low though as git cmd line tool guides your through the steps
  • Need to switch to a distributed VCS mindset
  • Better dev life cycle with Pull Requests
    • One-click PR creation - very fast
    • One-click PR merge
    • Git prevents conflicting PRs from being merged
    • Webhooks for Jenkins CI/CD

Questions?

[ Thank you ]

an introduction to Git

By Fabio Pitino

an introduction to Git

  • 614