Comprehensive Guide to Common Git Commands for GitHub Workflow

Here is a list of more common Git commands used for various operations in a GitHub workflow, along with brief descriptions to help you understand their usage:

Basic Local Repository Operations

  • git init: Initializes a new Git repository in the current directory.
  • git clone [url]: Clones a repository from GitHub to your local machine.
  • git add [file]: Adds files to the staging area before committing.
  • git commit -m "message": Commits the staged changes to the local repository, along with a descriptive message.

Branch Management

  • git branch: Lists all local branches in the current repository.
  • git branch [name]: Creates a new branch named [name].
  • git checkout [branch-name]: Switches to the specified branch and updates the working directory.
  • git branch -d [branch-name]: Deletes the specified branch.

Working with Remotes

  • git remote add [name] [url]: Adds a new remote Git repository as a shortcut named [name].
  • git fetch [remote]: Downloads all changes from the remote but doesn’t merge them.
  • git pull [remote] [branch]: Fetches the specified remote’s copy of the current branch and immediately merges it into the local copy.
  • git push [remote] [branch]: Pushes the branch to the remote, along with all commits and branches.

Inspection and Comparison

  • git status: Shows the working directory status, including uncommitted changes.
  • git log: Shows the commit logs.
  • git diff: Compares what is in your working directory with what is in your staging area.

Stash

  • git stash: Temporarily shelves (or stashes) changes you’ve made to your working directory so you can work on something else, and then come back and re-apply them later on.
  • git stash pop: Applies stashed changes back to your working directory.

Merging and Rebasing

  • git merge [branch]: Merges the specified branch into the current branch.
  • git rebase [branch]: Reapplies commits on top of another base tip.

Tagging

  • git tag [tag-name]: Used to mark specific points in history as important, typically used for releases.

Advanced Inspection

  • git blame [file]: Shows what revision and author last modified each line of a file.
  • git bisect: Uses binary search to find the commit that introduced a bug.

These commands form the foundation of interacting with Git and GitHub, providing a robust set of tools for managing and collaborating on software projects. Each command is crucial for different aspects of a developer’s workflow, from simple updates to complex branch management and code reviews.

Hello, I’m Anuj. I make and teach software.

My website is free of advertisements, affiliate links, tracking or analytics, sponsored posts, and paywalls.
Follow me on LinkedIn, X (twitter) to get timely updates when I post new articles.
My students are the reason this website exists. ❤️

Feedback Display