Git and Gerrit usages.

👉 Git is a free and open source distributed version control system (DVCS).
👉 Gerrit is Code Review server with:-

ℹ️ Disclaimer: Further content can be opinionated. 😇

Other major version control system :-

  • Perforce : Proprietary product Helix Core launched in 1995.
  • BitKeeper : Originally proprietary lately open-source under Apache 2.0, was used in Linux kernel development (2002 – April 2005).
  • Apache Subversion : Client-server model inspired by CVS:
  • Mercurial : Written in Python as Open Source replacement to BitKeeper.
  • GNU Bazaar : Bazaar is written in Python and part of the GNU Project.

Git protocols :-

Git repo can be cloned using following protocol:-

  • ssh://[user@]host.xz[:port]/path/to/repo.git/
  • git://host.xz[:port]/path/to/repo.git/
  • http[s]://host.xz[:port]/path/to/repo.git/
  • ftp[s]://host.xz[:port]/path/to/repo.git/

👉 https need user credentials for write access to repo.
👉 git protocol lack authentication on server side. It is paired with ssh/https for write access to repo.

ℹ️ Git Staging area.

h:5em

  • git status : Show all git tracked file changes along with state of stage.
  • git commit -a : Move all tracked and modified files to stage area and commit.
  • git add <filename> : Move particular file from working area to stage area.
ℹ️ Git Commit flow.
ℹ️ Git Branching.

h:5em

  • git branch -a : Show all git branches including remote and local.
  • git branch -r : Show all remote git branches.
  • git checkout -b <branch-name> : Create new git branch from current git branch with branch-name.
ℹ️ Git Merge.

Assume the following history exists and the current branch is master.

      A---B---C topic
     /
    D---E---F---G master

After git merge topic runs successfully.

      A---B---C topic
     /         \
    D---E---F---G---H master
ℹ️ Git Rebase.

Assume the following history exists and the current branch is "topic":

          A---B---C topic
         /
    D---E---F---G master

After running any of following commands :-
git rebase master
git rebase master topic

                  A'--B'--C' topic
                 /
    D---E---F---G master
  • Same command as pushing to Git with one Gerrit speciality: The target branch is prefixed with refs/for/
    git push origin HEAD:refs/for/<branch-name>
  • Example:
    git push origin HEAD:refs/for/mastersame as git push origin HEAD:refs/for/refs/heads/master
  • Push directly to Git (bypassing code review):
    git push origin HEAD:<branch-name>
  • Example:
    git push origin HEAD:mastersame as git push origin HEAD:refs/heads/master
ℹ️ Gerrit commands.
ℹ️ Opinionated workflow for development.
  • Clone repo from gerrit with commit-msg-hook
  • Never use remote git branches for making local changes.

Example: Create gerrit change-list(CL) for BWVONE-19 from master:-

git checkout master
git checkout -b BWVONE-19
git pull origin master --rebase
<Do some work and commit changes>
git push -vv ssh://<gerrit-username><repo-path>/<repo-name> HEAD:refs/for/master
ℹ️ Git LFS.

Git LFS : An open source Git extension for versioning large files.

Install git-lfs on machine :-
brew install git-lfs

git lfs install
git lfs track "*.psd"
git add .gitattributes

git add file.psd
git commit -m "Add design file"
git push origin master

References :-