Table of contents
What is git?
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. Git is used to track changes in the source code, enabling multiple developers to work together on non-linear development. Linus Torvalds created Git in 2005 for the development of the Linux kernel.
Advantage of Git
- Tracks history
- Free and open source
- Supports non-linear development
- Creates backups
- Scalable
- Supports collaboration
- Branching is easier
- Distributed development
Workflow of Git
Git Commands
git Add
Moves changes from the working directory to the staging area.
git branch
This command is your general-purpose branch administration tool.
git checkout
In addition to checking out old commits and old file revisions, git checkout is also the means to navigate existing branches.
git clean
Removes untracked files from the working directory.
git clone
Creates a copy of an existing Git repository.
git commit
Takes the staged snapshot and commits it to the project history.
git commit --amend
Passing the --amend flag to git commit lets you amend the most recent commit.
git config
A convenient way to set configuration options for your Git installation.
git fetch
Fetching downloads a branch from another repository, along with all of its associated commits and files.
git init
Initializes a new Git repository.
git log
Let's explore the previous revisions of a project. It provides several formatting options for displaying committed snapshots.
git merge
After forking the project history with git branch, git merge lets you put it back together again. A powerful way to integrate changes from divergent branches.
git pull
Pulling is the automated version of git fetch. It downloads a branch from a remote repository, then immediately merges it into the current branch.
- `git push'
Pushing is the opposite of fetching (with a few caveats). It lets you move a local branch to another repository, which serves as a convenient way to publish contributions.
git rebase
Rebasing lets you move branches around, which helps you avoid unnecessary merge commits.
git rebase -i
The -i flag is used to begin an interactive rebasing session. This provides all the benefits of a normal rebase, but gives you the opportunity to add, edit, or delete commits along the way.
git reflog
Git keeps track of updates to the tip of branches using a mechanism called reflog. This allows you to go back to changesets even though they are not referenced by any branch or tag.
git remote
A convenient tool for administering remote connections. Instead of passing the full URL to the fetch, pull, and push commands, it lets you use a more meaningful shortcut.
git reset
Undoes changes to files in the working directory. Resetting lets you clean up or completely remove changes that have not been pushed to a public repository.
git revert
Undoes a committed snapshot. When you discover a faulty commit, reverting is a safe and easy way to completely remove it from the code base.
git status
Displays the state of the working directory and the staged snapshot. You’ll want to run this in conjunction with git add and git commit to seeing exactly what’s being included in the next snapshot.