Session2 - Introduction To GitLab
Session2 - Introduction To GitLab
Git, a powerful version control system used by developers all over the world. Git helps us track
changes in our code, collaborate effectively with others, and revert to previous versions if
needed. Whether you're a seasoned programmer or just starting out, Git is an essential tool to
have in your arsenal.
Git is a bit different from traditional version control systems. It's a distributed system, which
means that every developer has a complete copy of the codebase. This allows for offline work
and makes collaboration much smoother. Git is also incredibly fast and efficient, even for large
projects with massive amounts of code.
Benefits of using Git
Installer will install git and gitbash Ex : If using ubuntu Brew :brew install git
Gitbash emulate sort of Linux behavior apt-get install git MacPorts : sudo port install git
Command Line and GUI
Gitbash , terminal or command Git GUI comes with Git Source tree or extensions helps
line can be used to execute git installation and helps to to provide more insights on
commands perform git operations the time lines of commits,
options to revert etc.
Git Configuration
Commit Add
Git Workflow Commands
Only leads/Managers
Master Source of truth UAT or performance envs
will be able to merge
Any prod issues are All developers will have access to Merged into Master after
Hotfix/Bugfix fixed in hotfix or Create and MR’s will be unit testing
bugfix branches merged by leads or Managers
Created from Release or transition management Merged into beta or prod after
Release master to deploy teams can have access to deploy UAT and pert testing acceptance
into beta or prod
Git Merge
• Assume a scenario, where developer wants to merge changes from develop to master
• Steps involved are
• Make sure you are in develop branch and execute below commands to pull changes into
develop
• Git checkout develop
• Git pull origin develop
• Change the branch to the master
• Git checkout master
• Git merge develop
• Pull changes from the remote repository and merge them into the current branch
• git pull origin main
By default, Git does not create an extra merge commit when merging a commit that is a
descendant of the current commit. Instead, the tip of the current branch is fast-forwarded.
When set to false, this variable tells Git to create an extra merge commit in such a case
(equivalent to giving the --no-ff option from the command line). When set to only, only such
fast-forward merges are allowed (equivalent to giving the --ff-only option from the
elopers are working on the same branch, using git rebase can create synchronization issues, as it requires everyone to force update ( git push --force) their branches, which ca
1 Rewriting History
Loss of Original Context: Rebasing rewrites commit history, which means that the original context of how
branches diverged and merged is lost. This can make it harder to understand the historical sequence of
events in a project.
Changing Commit SHA-1: Every rebased commit gets a new SHA-1 hash, which effectively creates new
commits. This can confuse collaborators who might have already based their work on the original commits.
2 Collaboration
Conflicts with Shared Branches: Rebasing public or shared branches can cause significant problems. If other
developers have based their work on commits that you have rebased, they will need to reconcile their work
with the new commit history, leading to potential merge conflicts and confusion.
Difficulties in Synchronization: When multiple developers are working on the same branch, using git rebase
can create synchronization issues, as it requires everyone to force update (git push --force) their branches,
which can be risky.
Why should we avoid git rebase
3 Impact on Code Reviews
Difficulty in Tracking Changes: Rebasing can make code reviews more difficult, as it changes commit hashes
and can make it harder for reviewers to track what changes have been made compared to a merge-based
workflow.
Loss of Incremental Context: Rebasing can strip away the incremental context provided by merge commits,
making it harder to understand the development process and review changes comprehensively.
4 Force Pushing
Risk of Data Loss: After rebasing, you often need to use git push --force to update the remote branch. Force
pushing can potentially overwrite changes on the remote repository if not used carefully, leading to data loss.
Override Protection Mechanisms: Force pushing bypasses the usual protection mechanisms that prevent
accidental overwrites, increasing the risk of mistakes.
Best Practices