Git: Streamlining Code Collaboration and Version Control for Developers


Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Basic Git Commands

  • git branch - List all branches in the repository
  • git status - Show the working tree status
  • git pull - Fetch from and integrate with another repository or a local branch
  • git push - Update remote refs along with associated objects
  • git checkout -b [branchname] - Create a new branch and switch to it
  • git merge [branch] - Merge changes from a branch into the current branch
  • git stash - Temporarily save changes that you don’t want to commit yet
  • git fetch - Download objects and refs from another repository
  • git clone [repository] - Clone a repository into a new directory
  • git remote - Show a list of remote repositories
  • git diff - Show changes between commits, commit and working tree, etc.
  • git log - Show commit logs
  • git rm [file] - Remove a file from the working tree and the index
  • git mv [file] [new-file] - Move or rename a file, directory, or symlink

Repository History Manipulation

  • rm -rf .git - Remove the history from the repository
  • git init - Initialize a new Git repository
  • git add . - Add all files to the staging area
  • git commit -m "Initial commit" - Commit the staged changes with a message
  • git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git - Add a remote repository
  • git push -u --force origin master - Push to the GitHub remote repository, overwriting history

Submodules

  • git submodule init - Initialize Git submodules
  • git submodule update - Update Git submodules

Global Configuration

  • git config --global user.email "jasper@duizendstra.com" - Set the global user email
  • git config --global user.name "Jasper Duizendstra" - Set the global user name

Git Naming Conventions

  • wip: Works in progress; stuff that won’t be finished soon
  • feat: Feature being added or expanded
  • bug: Bug fix or experiment
  • junk: Throwaway branch created to experiment

Resources