Git

Git Cheatsheet #

Git is a distributed version control system created by Linus Torvalds in 2005 to manage the development of the Linux kernel. It is designed for speed, efficiency, and support for distributed, non-linear workflows. Git has become the most widely used version control system in the world, known for its branching and merging capabilities.

Repository Management #

Command/OptionExampleDescription
git initgit initInitialize a new Git repository
git clonegit clone https://github.com/user/repo.gitClone an existing repository

Staging and Committing #

Command/OptionExampleDescription
git addgit add file.txtAdd file contents to the index
git commitgit commit -m "Commit message"Record changes to the repository
git statusgit statusShow the working tree status
git diffgit diffShow changes between commits, commit and working tree, etc.

Branching and Merging #

Command/OptionExampleDescription
git branchgit branch new-branchList, create, or delete branches
git checkoutgit checkout new-branchSwitch branches or restore working tree files
git mergegit merge new-branchJoin two or more development histories together
git rebasegit rebase masterReapply commits on top of another base tip

Remote Repositories #

Command/OptionExampleDescription
git fetchgit fetch originDownload objects and refs from another repository
git pullgit pull origin masterFetch from and integrate with another repository or a local branch
git pushgit push origin masterUpdate remote refs along with associated objects
git remotegit remote add origin https://github.com/user/repo.gitManage set of tracked repositories

Undoing Changes #

Command/OptionExampleDescription
git resetgit reset --hard HEAD~1Reset current HEAD to the specified state
git rmgit rm file.txtRemove files from the working tree and the index
git stashgit stashStash the changes in a dirty working directory away

Viewing History and Logs #

Command/OptionExampleDescription
git loggit logShow commit logs
git showgit show HEADShow various types of objects
git refloggit reflogShow history of commands associated with the reference

Advanced Commands #

Command/OptionExampleDescription
git taggit tag -a v1.0 -m "Version 1.0"Create, list, delete, or verify a tag object signed with GPG
git archivegit archive -o archive.zip HEADCreate an archive of files from a named tree
git bisectgit bisect startUse binary search to find the commit that introduced a bug
git cherry-pickgit cherry-pick commitSHAApply the changes introduced by some existing commits

This cheatsheet covers the most commonly used Git commands and options, helping you to manage repositories, commits, branches, merges, and more effectively.

Git

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.