3 Git Commands Every Front-End Developer Needs to Know

3 Git Commands Every Front-End Developer Needs to Know

Here's 3 Git commands I think every front-end developer needs to know to help track and manage your web development projects. Diff, merge, and commit changes to keep your project, branches, and development team in-sync.

Diff a Specific File Between Two Branches

git diff branch-one..branch-two path/to/file

This CLI Git command uses double-dot syntax to run a diff of a specific file between versions on two different branches. It's useful for comparing the differences – or changes made – between the same file on separate branches. I frequently use this type of diff when consolidating and merging feature branches and hot-fixes on a project.

Merge a Specific File from Another Branch

git checkout source_branch <paths>

This CLI Git command takes a file from another branch and checks it in to your current branch – accepting the checked-in file as your new source instead of whatever you had before. It's useful when you want to accept all changes to a file after running a diff or resolving merge conflicts.

Stage and Commit Changed Files

git add -u
git commit -m "Description of your changes"
git push

git add -u stages all updated files for a commit – that's what the -u means.

git commit -m “message” lets you add a meaningful message to your commits, so later on when you look at the commits you'll know what changes you made in this specific commit.

git push pushes your staged commits into your remote repositories.