Bratish Goswami

Personal website and blog

Git Workflow Tips for Better Development

Been using Git more seriously lately and picking up some good practices. Coming from SVN, Git's flexibility is both powerful and confusing.

Basic Workflow

My current daily workflow looks like this:

git status                    # Check what's changed
git add .                     # Stage changes
git commit -m "Description"   # Commit with message
git push origin master        # Push to remote

Branching Strategy

Creating feature branches for each new feature:

git checkout -b new-feature
# Work on feature
git add .
git commit -m "Implement new feature"
git checkout master
git merge new-feature
git branch -d new-feature

Useful Commands I've Learned

Checking History

git log --oneline            # Compact log
git log --graph              # Visual branching
git show HEAD~1              # Show previous commit

Undoing Changes

git checkout -- filename    # Discard file changes
git reset HEAD filename      # Unstage file
git reset --hard HEAD~1      # Undo last commit (dangerous!)

Remote Management

git remote -v                # List remotes
git fetch origin             # Get latest from remote
git pull origin master       # Fetch and merge

Configuration

Essential config settings:

git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --global color.ui auto
git config --global push.default simple

.gitignore

Always create a good .gitignore:

# Dependencies
node_modules/
*.pyc
*.class

# Build outputs
dist/
build/
*.o

# IDE files
.DS_Store
Thumbs.db
*.swp

Commit Messages

Good commit message format:

Short (50 chars or less) summary

More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. The blank line separating the summary from the body
is critical; tools like rebase can get confused if you run the two
together.

- Bullet points are okay too
- Use present tense: "Fix bug" not "Fixed bug"

Collaborating

When working with others:

git fetch origin             # Get latest changes
git rebase origin/master     # Replay your changes on top
git push origin master       # Push your changes

Common Mistakes

Things I've learned not to do:

  1. Don't commit large binary files - they bloat the repo
  2. Don't commit passwords/keys - use environment variables
  3. Don't force push unless you really know what you're doing
  4. Don't work directly on master - use feature branches

Helpful Aliases

This is how my .gitconfig looks like:

[color]
    diff = auto
    status = auto
    branch = auto
[core]
    excludesfile = ~/.gitignore
    editor = vim
    autocrlf = input
[alias]
    ci = commit
    co = checkout
    c = commit -m
    a = add
    di = diff
    dic = diff --cached
    pl = pull
    ps = push
    plre = pull --rebase
    st = status
    out = log origin..HEAD
    br = branch
    bra = branch -a
    f = fetch

[user]
    name = Bratish Goswami
    email = bratishgoswami@gmail.com
[mergetool "diffmerge"]
    cmd = diffmerge --merge --result=$MERGED $LOCAL $BASE $REMOTE
    trustExitCode = false

[filter "lfs"]
    clean = git-lfs clean -- %f
    smudge = git-lfs smudge -- %f
    process = git-lfs filter-process
    required = true

Git has a steep learning curve but it's worth the investment. Much more powerful than SVN once you get comfortable with it.