Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Essential Git Workflow and Command Reference

Tech May 8 3

Core Data Flow

Working Directory → Staging Area → Local Repository → Remote Repository

Daily Commands

Push with Safety Net

git pull --rebase   # fetch + rebase to avoid merge bubbles
git push            # send current branch upstream

git push -f origin feature-x  # only after history rewrite
git push --all origin         # publish every local branch

Rewriting History

# Rebase feature onto latest main
# Before:
# main:   A---B---C
#           \
# feature:   D---E---F

git checkout feature
git rebase main

# After:
# main:   A---B---C
#                   \
# feature:           D'--E'--F'

Merging Branches

git checkout main
git merge hotfix

# Result:
# main:   A---B---M
#           \     /
# hotfix:    C---D

Branch Manipulation

git branch -f master HEAD~3   # move master three commits back

Undoing Changes

git reset --hard HEAD~1   # discard last commit (dangerous)
git revert HEAD~1         # create new commit that undoes previous one

Clone with Submodules

git clone --recurse-submodules https://repo.url/project.git
# or
git clone https://repo.url/project.git
git submodule update --init --recursive

Publishing a Local Project

Remote Already Has Content

git init
git remote add origin https://repo.url/project.git
git fetch origin master
git branch --set-upstream-to=origin/master master
git add .
git commit -m "Initial import"
git push

Empty Remote

git init
git remote add origin https://repo.url/project.git
git add .
git commit -m "First commit"
git push -u origin master

Global Configuration

~/.gitconfig

[user]
	name  = Your Name
	email = you@example.com
[color]
	ui = auto
[credential]
	helper = store
[commit]
	template = ~/.gitmessage
[core]
	editor = code --wait

Common Pit Snags

  • Empty directories: Git tracks files only; add a .gitkeep placeholder.
  • Ignoring files: Create .gitignore and list patterns:
    node_modules/
    *.log
    .env
    

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.