About
What is this "Git" everyone keeps talking about?
Git is a distributed version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows.
Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development. Its current maintainer since 2005 is Junio Hamano. As with most other distributed version-control systems, and unlike most client–server systems, every Git directory on every computer is a full-fledged repository with complete history and full version-tracking abilities, independent of network access or a central server.
Git is free and open-source software distributed under the terms of the GNU General Public License version 2.
Download Git Wikipedia PageConfigure Git
Learn how to configure user information on your local repositories.
- Configure User Name Attached to Commits
- Configure Email Attached to Commits
- Enable Colorization of Command Outputs
$ git config --global user.name "[name]"
$ git config --global user.email "[email address]"
$ git config --global color.ui auto
Clone Repositories
Learn how to download an existing repository to your local computer.
Git clone is a command for downloading existing source code from a remote repository (like Github, for example). In other words, Git clone basically makes an identical copy of the latest version of a project in a repository and saves it to your computer.
- Clone A Repository with an SSH Key
- Clone A Repository with HTTPS
$ git clone [SSH Key]
$ git clone [URL]
Create Repositories
Learn how to create a new repository locally.
When starting out with a new repository, you only need to do it once; either locally, then push to GitHub, or by cloning an existing repository.
- Create A New Git Repository
- Link The Local Repository To Empty GitHub Repository
- Verify The Remote Repository Was Linked
$ git init
$ git remote add origin [URL]
$ git remote -v
Git Branches
Learn how to work with git branches.
Branches are highly important in the git world. By using branches, several developers are able to work in parallel on the same project simultaneously. We can use the git branch command for creating, listing and deleting branches.
- Create A New Local Branch
- Switch To The Specified Branch
- Combine The Specified Branch's History Into The Current Working Branch
- Delete The Specified Branch
- Viewing Branches
$ git branch [branch name]
$ git checkout [branch name]
$ git merge [branch name]
$ git branch -d [branch name]
$ git branch or $ git branch --list
Making Changes
Learn how to handle and view changes on a branch.
- The Most Useful Command You Can Run
- Whether the current branch is up to date.
- Whether there is anything to commit, push or pull.
- Whether there are files staged, unstaged or untracked.
- Whether there are files created, modified or deleted.
- Browse & Inspect The Evolution of Project Files
- List Version History For The Current Branch
- List Version History For A FIle (Renames As Well)
- Show Content Differences Between Two Branches
- Include Changes of A File Into The Next Commit
- Include Changes of Everything At Once
- Save Changes (One Of The Most Used Commands)
$ git status
The Git status command gives us all the necessary information about the current branch:
$ git log
$ git log --follow [file]
$ git diff [first branch]...[second branch]
$ git show [commit]
$ git add [file name]
$ git add -A
$ git commit -m "commit message"
Note: Best practice is to write a short message to explain what you have developed or changed in the source code.
Updating A Repository
Learn how to send your changes to the remote server after commiting changes.
- Upload Commit To Remote Repository
- Update Local Working Branch From Remote Branch
$ git push [remote] [branch name] or $ git push origin [branch name]
$ git pull [remote]
Revert Changes
Learn how to undo the changes that have been made.
- Undo All Commits After [commit], Preserving Changes Locally
- Discard All History & Change Back to Specified Commit
- Undo Changes Made Without Touching Commit History
$ git reset [commit]
$ git reset --hard [commit]
$ git revert [hash code of commit]
References
Sources for documentation information.
All of the information and documentation for this page was provided by two sources, freeCodeCamp & GitHub.
