GithubHelp home page GithubHelp logo

git-basics-cheatsheet's Introduction

Git Cheatsheet (Basics)

This cheatsheet is a list of our most used Git commands, and it countains useful information for those who are getting started.

Glossary

Keywords Description
git Open-source distributed version-control system, used to store code in repositories
GitHub, GitLab and Bitbucket Platform for hosting and collaborating on Git repositories
staging Proposed files/directories that you'd like to commit
commit Saving all staged files/directories to your local repository
branch An independent line of development, so you can develop features isolated from each other. Master branch is the default.
clone Local version of a repository, including all commits and branches
remote Common repository on eg. Github that all team members to keep that changes in sync with
fork Copy of a repository owned by a different user
pull request A method of submitting contributions to a repository
HEAD Represents your current working directory

Configuration

Key/Command Description
git config --global user.name [name] Set author name to be used for all commits
git config --global user.email [email] Set author email to be used for all commits
git config color.ui true Enables helpful colorization of command line output

Core Commands

Key/Command Description
git init [directory] Creates new local repository
git clone [repo] Creates local copy of remote repository
git add [directory] Stages specific [directory]
git add [file] Stages specific [file]
git add -A Stages all changed files
git add . Stages new and changed files, NOT deleted files
git add -u Stages changed and deleted files, NOT new files
git commit -m "[message]" Commit everything that is staged
git status Shows status of changes as untracked, modified or staged

Synchronization of Changes

Key/Command Description
git fetch Downloads all history from the remote branches
git merge Merges remote branch into current local branch
git pull Downloads all history from the remote branch and merges into the current local branch
git push Pushes all the commits from the current local branch to its remote equivalent

Tip: git pull is the combination of git fetch and git merge

Undo Changes

Key/Command Description
git checkout -- [file] Replace file with contents from HEAD
git revert [commit] Create new commit that undoes changes made in [commit], then apply it to the current branch
git reset [file] Remove [file] from staging area
git reset --hard HEAD Removes all local changes in working directory
git reset --hard [commit] Reset your HEAD pointer to previous commit and discard all changes since then

Branches

Key/Command Description
git branch [branch] Create a new branch
git checkout [branch] Switch to that branch
git checkout -b [branch] Create and checkout new branch
git merge [branch] Merge [branch] into current branch
git branch -d [branch] Deletes the [branch]
git push origin [branch] Push [branch] to remote
git branch Lists local branches
git branch -r Lists remote branches
git branch -a Lists local and remote branches

History

Key/Command Description
git log Lists version history for the current branch
git log --author=[name] Lists version history for the current branch from certain author
git log --oneline Lists compressed version history for the current branch
git show [commit] Outputs metadata and content changes of the specified commit
git blame [file] Shows who changed what and when in file

Gitignore

You can list files/directories that you want to explicitely exclude from Git in a .gitignore file. This file should be placed at the root of your repository.

It is noted that people usually exclude dependency caches, such as node_modules, system files, such as .DS_Store, among others.

You can see the .gitignore file of this repository or more examples provided by GitHub.

Platforms

The following platforms can be used to host your repositories.

Platform Price
GitHub Free
GitLab Free
Bitbucket Free

Graphical User Interface (GUI)

Is the command-line interface not for you? Try one of the following clients.

Clients Operational System Price
Github Mac and Windows Free
Source Tree Mac and Windows Free
Tower MacOS and Windows $69 to $99

Resources

git-basics-cheatsheet's People

Contributors

0nn0 avatar teuscard avatar nbarnhouse avatar paulkaefer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.