0% found this document useful (0 votes)
7 views7 pages

VesionControl Advanced

The document provides a comprehensive guide on advanced Git techniques, including managing large repositories with Git LFS, advanced branching strategies like Git Flow and GitHub Flow, and the differences between rebasing and merging. It also covers squashing commits, using submodules, configuring Git settings and aliases, performance optimization, continuous integration practices, best collaborative workflows, and understanding Git architecture. Each section includes commands and examples to illustrate the concepts effectively.

Uploaded by

Thanh Pham Minh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

VesionControl Advanced

The document provides a comprehensive guide on advanced Git techniques, including managing large repositories with Git LFS, advanced branching strategies like Git Flow and GitHub Flow, and the differences between rebasing and merging. It also covers squashing commits, using submodules, configuring Git settings and aliases, performance optimization, continuous integration practices, best collaborative workflows, and understanding Git architecture. Each section includes commands and examples to illustrate the concepts effectively.

Uploaded by

Thanh Pham Minh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Advanced Print

Managing large repositories with Git LFS Tutorial


Managing large repositories can be challenging when it comes to version control due to the increased
size of binary files or large datasets. Git LFS (Large File Storage) is an extension for Git that allows you
to work with large files more efficiently by replacing them with pointers in Git while storing the actual file
contents on a remote server. This approach not only speeds up cloning and fetching operations but also
keeps your repository lightweight and manageable.
Copy
Initialize Git LFS
git lfs install

Track large files


git lfs track "*.psd"

Check .gitattributes file


cat .gitattributes

Add and commit changes


git add .gitattributes && git add <large file> && git commit -m "Add large file with Git
LFS"

Push changes to remote


git push origin main

Advanced branching strategies (Git Flow, GitHub Flow) Tutorial


Advanced branching strategies like Git Flow and GitHub Flow help teams manage their development
workflow effectively. Git Flow is a branching model that uses multiple branches for different
environments, with a clear distinction between feature, develop, and master branches. GitHub Flow is a
simpler strategy that focuses on using a single branch for development, merging changes into the
master branch through pull requests. Both strategies promote organized collaboration and integration
of changes in software projects.
Copy
Git Flow Example
# Initialize a new Git Flow repository
$ git init

# Start Git Flow


$ git flow init

# Create a new feature branch


$ git flow feature start my-feature

# After completing your feature, finish it


$ git flow feature finish my-feature
# Merge the develop branch into the master branch for release
$ git flow release start 1.0.0
$ git flow release finish 1.0.0

GitHub Flow Example


# Create a new branch for your feature
$ git checkout -b my-feature

# Make changes to your files and stage and commit them


$ git add .
$ git commit -m 'Add new feature'

# Push your branch to GitHub


$ git push origin my-feature

# Create a pull request in GitHub to merge my-feature into master


# Review, approve, and merge the pull request

Rebasing vs. merging Tutorial


Rebasing and merging are two essential strategies in Git for integrating changes from one branch into
another. Merging creates a new commit that combines the changes from the two branches, preserving
the history of both branches. In contrast, rebasing involves moving the entire base of one branch to a
new commit, resulting in a linear history without the merge commit. While merging is straightforward
and retains historical context, rebasing streamlines the commit history, making it cleaner and easier to
follow.
Copy
Merging branches
git checkout feature-branch
git merge main

Rebasing a feature branch onto main


git checkout feature-branch
git rebase main

Resolving conflicts during rebase


git status
# Check for conflicts
git add <resolved-file>
git rebase --continue

Aborting a rebase
git rebase --abort

Squashing commits Tutorial


Squashing commits is a Git feature that allows you to combine multiple commits into a single commit.
This is often used to simplify the commit history before merging branches or to clean up a series of
commits that represent a particular feature or bug fix. Squashing helps maintain a cleaner project
history and makes it easier for other developers to understand the changes made.
Copy
Squash the last three commits
git rebase -i HEAD~3

Using interactive rebase to squash


# In the interactive rebase editor, change 'pick' to 'squash' for the commits you want to
combine.
# Save and exit the editor to finalize.

Squash when merging a branch


git merge --squash feature-branch

Rebasing with squash after rebase


git rebase -i --autosquash

Using submodules in Git Tutorial


Submodules in Git allow you to include and manage external repositories within your own repository,
enabling you to keep track of dependent projects. This is useful when you want to incorporate libraries
or shared code that are maintained in separate repositories, ensuring that updates or changes to these
dependencies are managed effectively without merging all their code directly into your main project.
Copy
Add a Submodule
git submodule add https://github.com/example/repo.git path/to/submodule

Initialize and Update Submodules


git submodule init

git submodule update

Clone a Repository with Submodules


git clone --recurse-submodules https://github.com/example/repo.git

Update Submodules to the Latest Commit


git submodule update --remote

advertisement
Configuration and aliases in Git Tutorial
Configuration and aliases in Git allow users to customize their Git environment and streamline their
workflows. By modifying the configuration settings, users can set user-specific options, such as user
name and email, line endings, and default behaviors for commands. Aliases enable users to create
shorthand commands for commonly used Git commands, enhancing efficiency in version control
operations.
Copy
Set user name and email
git config --global user.name 'Your Name'
git config --global user.email '[email protected]'

Create an alias for 'git status'


git config --global alias.s status
Create an alias for 'git checkout'
git config --global alias.co checkout

View current Git configuration settings


git config --list

Create an alias for 'git log --oneline'


git config --global alias.lg 'log --oneline'

Performance optimization for Git operations Tutorial


Performance optimization for Git operations involves techniques and practices that improve the speed
and efficiency of Git commands, especially when working with large repositories or a significant number
of files. This can include adjusting configuration settings, using command-line options wisely, and
understanding how Git handles data internally to minimize performance bottlenecks.
Copy
Using Git config to optimize fetch size
git config --global pack.windowMemory 10m

Using Git GC to cleanup unnecessary files


git gc --aggressive --prune=now

Increasing the performance of status command


git config --global status.showUntrackedFiles all

Using sparse-checkout for large repositories


git sparse-checkout init --cone
git sparse-checkout set <directory>

Optimizing cloning via depth option


git clone --depth 1 <repository-url>

Using continuous integration with version control Tutorial


Using continuous integration (CI) with version control allows developers to automatically test and
integrate code changes into a shared repository multiple times a day. This practice enhances
collaboration, reduces integration issues, and promotes early detection of bugs by running automated
tests whenever new code is pushed to the repository.
Copy
Basic CI Configuration with GitHub Actions
name: CI

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js


uses: actions/setup-node@v2
with:
node-version: '14'

- name: Install dependencies


run: npm install

- name: Run tests


run: npm test

Travis CI Configuration Example


language: node_js

node_js:
- '14'

script:
- npm install
- npm test

branches:
only:
- main

Jenkins Pipeline for CI


pipeline {
agent any

stages {
stage('Checkout') {
steps {
git 'https://github.com/user/repository.git'
}
}

stage('Build') {
steps {
sh 'npm install'
}
}

stage('Test') {
steps {
sh 'npm test'
}
}
}
}

Best practices for collaborative workflows Tutorial


Best practices for collaborative workflows in version control focus on enhancing team communication
and efficiency while minimizing conflicts and errors. These practices include using feature branches for
new developments, making frequent commits with clear messages, conducting code reviews through
pull requests, and regularly synchronizing with the main branch to keep local changes up to date.
Leveraging automated CI/CD pipelines can also ensure that code is continuously integrated and tested
upon integration.
Copy
Creating a Feature Branch
git checkout -b feature/new-feature

Committing Changes with a Clear Message


git add . && git commit -m 'Add new feature X implementation'

Submitting a Pull Request


git push origin feature/new-feature

Synchronizing with the Main Branch


git fetch origin && git rebase origin/main

Setting Up a CI/CD Pipeline


name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
run: npm test

Understanding the Git architecture Tutorial


Understanding the Git architecture involves learning about the underlying concepts and structures that
make Git function effectively. At its core, Git consists of objects (commits, trees, blobs, tags),
references (branches, tags, HEAD), and a series of commands that manipulate these objects to manage
versions of your project. This architecture allows Git to efficiently handle and track changes, enabling
features like branching, merging, and history tracking.
Copy
Viewing commit object
git cat-file -p <commit-hash>

Listing objects in the repository


git rev-list --objects --all

Viewing the current HEAD


git rev-parse HEAD

Exploring the structure of a tree object


git cat-file -p <tree-hash>
Understanding references
git show-ref

You might also like