Git š

JiÅĆ Urban, TomĆ”Å” JuÅiÄka, Stanislav ÄermĆ”k, KarolĆna NesrstovĆ”, David Dlugosz, TomĆ”Å” TrÄka

Commit vs. Push ā

-
Commit
- Saves repo changes on local repo
-
Push
- Commit + sends changes to remote repo

Fetch vs. Pull ā


-
Fetch
- Downloads changes from the remote to your local repo
- Pull
- Fetch + merges them into your current branch
Head š


- Pointer to (the latest) commit
Working directory š
/ tree / copy


- Dir on local machine where Git repo was cloned or inited
- You can make changes here
- Can be lost when switching branches or pulling changes
Checkout branch ā


- Switch to a different branch in your repo
-
Make it āactiveā so you can make changes there
Ā - Git updates files in your working dir
- Changes are then specific to that branch
Stash changes

-
Save changes to the working dir which are not yet committed
-
Allow to temporarily switch to another branch

Stage changes


- Preparing changes to be included in the next commit
Git Merge Conflict āļø


- Attempt to merge two branches with conflicting changes
- Auto merge fails
-
Manually resolve the changes
Ā - Can be time-consuming
- Avoid as much as possible
Pull request vs. Merge request ā


- Same result
- GitHub ~ pull r.
- GitLab ~ merge r.
- Reviewer (approve / reject)
Squash commits
- Combine multiple commits into a single commit
- Cleaner and more organized history

Git merge vs. rebase
- Both solve the same problem (forked commit history)
- Integrate changes from one branch into another (but in different ways)

Git merge
- Merge the āmainā branch into the feature branch
- Creates new commit in the āfeatureā branch
- Easier
- Non-destructive operation
- Existing branches arenāt changed
- But: additional merge commit

Git rebase
- Rebase āfeatureā branch onto āmainā
- Moves the entire āfeatureā branch at the end of the āmainā
- Re-writes the project history
-
Creates brand new commits
for each commit in the original branch
-
Much cleaner history
-
Linear project history
without forks -
But: safety + traceability

Git rebase 2 - Safety
-
Never rebase on public branches (e. g. āmainā onto āfeatureā)
-
My āmainā diverged from othersā main
-
Would have to merge them
back together -
āIs anyone else looking
at this branchā? -
If no, you can rebase

Git rebase 3 - Traceability
- Less important
- Loses the context provided by a merge commit
- Canāt see when upstream changes were merged into āfeatureā


Git Flow
- = Branching model (vs. trunk-based workflows)
- Feature branches
- Multiple primary branches
- Longer-lived branches
- Larger commits
- Higher risk of conflicting updates


Branches š³
(from start to end of a project)
-
Main
- Formerly āMasterā ā
- Production-ready code that can be released
-
Develop
- Pre-production code with new features which are being tested


Branches š (supporting)
-
Feature
- Most common
- Working on a new feature
- Based on: Develop
- Merged to: Develop (after review)
-
Release branch
- Preparing new production releases
- Finishing touches + minor bugs specific to release
-
Hotfix branch
- Quickly address necessary changes in Main branch
- Based on: Main
- Merged to: Main + Develop
Ā

Git tag š·ļø
-
Label to mark a specific point in the history (e. g. version)
-
= Reference to a specific commit


Best practices š
(clean and well-organized)
- Commits small and focused
- Branches to isolate changes
- Meaningful commit messages
- Regular fetch / pull
- Review before merge
- Use tags to mark releases
- Use ā.gitignoreā file (build artifacts, generated files)
- Use one branching strategy (by all members)


Best practices 2 šļø
- Do not nest (feature) branches
- Merge (feature) branches as soon as possible


GUI git tools š ļø
- Sourcetree ā free, for WIN and MAC
- GitKraken ā cross platform, integrates with GitHub, Bitbucket, GitLab
- GitHub Desktop
- GitLab ā web-based git repo manager (DevOps platform, CI/CD, wiki)
-
Bitbucket ā web-based git repo manager by Atlassian, integrates with Jira, Confluence
-
TortoiseGit ā Win-based, integrates with Win explorer


VTV - 2ndLesson - Git
By trckatomas
VTV - 2ndLesson - Git
- 51