Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Comprehensive Git Workflows: From Repository Setup to Advanced History Management

Tech 1

Repository Initialization and Cloning

Initialize a new Git repository in the current directorry:

git init

Clone a remote repository to your local machine:

git clone https://gitlab.com/acme-team/project-beta.git
cd project-beta

Daily Development Cycle

Check the current state of your working directory and staging area:

git status

Stage specific files for the next commit:

git add src/components/Header.vue
git add docs/api-reference.md

Record staged changes with a descriptive message:

git commit -m "Add responsive navigation and update API docs"

View unstaged modifications in your working tree:

git diff

Branching and Navigation

Display existing branches with the current branch highlighted:

git branch --list

Create a new isolated development context:

git branch feature/oauth-integration

Switch to a specific branch to begin work:

git checkout feature/oauth-integration
# Alternative modern syntax:
git switch feature/oauth-integration

Combine branch histories using a merge commit:

git checkout main
git merge feature/oauth-integration

Remote Collaboration

Download changes from a remote server and integrate them immediately:

git pull upstream develop

Upload local commits to a remote repository:

git push upstream develop

Retrieve remote changes without automatically merging:

git fetch upstream

Correcting Mistakes

Remove files from the staging area while preserving working directory modifications:

git restore --staged config/database.yml
# Legacy syntax:
git reset HEAD config/database.yml

Create a new commit that reverses the changes from a specific previous commit:

git revert 9f4e2d1

Advanced Repository Configuration

Modify the URL of an existing remote repository after migration:

git remote -v
git remote set-url origin https://github.com/corporate-platform/api-gateway.git
git remote -v

Selective History Editing

Apply a specific commit from another branch onto your current branch:

git cherry-pick 8a3b2c1

Condense multiple consecutive commits into a single cohesive commit using interactive rebase:

git rebase -i HEAD~3

In the text editor that opens, change the command from pick to squash (or s) for commits you want to absorb into the previous one:

pick 3f4a5b2 Initialize database schema
squash 7c8d9e0 Add performance indexes
squash 1a2b3c4 Fix foreign key constraints

If conflicts arise during the rebase process, resolve them manually and continue:

git rebase --continue

To abort the rebase and return to the original state:

git rebase --abort

Release Management with Tags

Create a lightweight tag serving as a simple reference to a commit:

git tag v3.5.0

Create an annotated tag containnig metadata (author, date, message):

git tag -a v3.5.0 -m "Production release with search optimization"

Remove tags from local and remote repositories:

git tag -d v3.5.0
git push origin --delete v3.5.0
# Alternative syntax:
git push origin :refs/tags/v3.5.0

Advanced History Visualization

View compact one-line-per-commit history:

git log --oneline -15

Display a decorated graph with custom formatting and color coding:

git log --all --graph --pretty=format:'%C(cyan)%h%Creset -%C(magenta)%d%Creset %s %Cgreen(%ci) %C(bold yellow)<%an>%Creset' --abbrev-commit

Filter commits by specific criteria:

git log --author="dev@company.com" --since="2 weeks ago" --grep="refactor" --no-merges

Show detailed file statistics and patch content for each commit:

git log --stat -p
Tags: git

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.