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 repositorygit status
- Show the working tree statusgit pull
- Fetch from and integrate with another repository or a local branchgit push
- Update remote refs along with associated objectsgit checkout -b [branchname]
- Create a new branch and switch to itgit merge [branch]
- Merge changes from a branch into the current branchgit stash
- Temporarily save changes that you don’t want to commit yetgit fetch
- Download objects and refs from another repositorygit clone [repository]
- Clone a repository into a new directorygit remote
- Show a list of remote repositoriesgit diff
- Show changes between commits, commit and working tree, etc.git log
- Show commit logsgit rm [file]
- Remove a file from the working tree and the indexgit mv [file] [new-file]
- Move or rename a file, directory, or symlink
Repository History Manipulation
rm -rf .git
- Remove the history from the repositorygit init
- Initialize a new Git repositorygit add .
- Add all files to the staging areagit commit -m "Initial commit"
- Commit the staged changes with a messagegit remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
- Add a remote repositorygit push -u --force origin master
- Push to the GitHub remote repository, overwriting history
Submodules
git submodule init
- Initialize Git submodulesgit submodule update
- Update Git submodules
Global Configuration
git config --global user.email "jasper@duizendstra.com"
- Set the global user emailgit 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
- Git - Official website and documentation
- How to Write a Git Commit Message - Best practices for crafting clear commit messages
- Pro Git Book - Comprehensive Git reference
- GitHub Guides - Official GitHub how-to guides
- Atlassian Git Tutorial - Beginner to advanced Git tutorials by Atlassian
- Git Cheat Sheet - A quick reference for Git commands
- Git Explorer - A helpful tool for finding the right Git command
- Learn Git Branching - An interactive tutorial for understanding Git branches
- Oh My Git! - A game designed to teach Git concepts