What is Git?
Git is a version control system for tracking computer file changes. It is generally used for source code management in software development.
- Git is used to track changes in the source code.
- The distributed version control tool is used for source code management.
- It allows multiple developers to work together.
- It supports non-linear development through its thousands of parallel branches.
Configure tooling
git config --global user.name "[name]"
Sets the name you want to be attached to all of the commits.
git config --global user.email "[email address]"
Sets the email you want to be attached to your commit transactions.
Creating repositories
git init
Turn an existing directory into a git repository.
git clone [url]
Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commit.
Branches
git branch [branch-name]
Creates a new branch.
git checkout [branch-name]
Switches to the specified branch and updates the working directory.
Synchronize changes
git fetch
Downloads all history from the remote tracking branches.
git merge
Combines remote-tracking branch into a current local branch.
git push
Uploads all local branch commits to GitHub.
git pull
Updates your current local working branch with all new commits from the corresponding remote branch on GitHub.
git pull
is a combination ofgit fetch
andgit merge
.
Make changes.
git log
Lists version history for the current branch.
git add [file]
Snapshots of the file in preparation for versioning.
git commit -m "[descriptive message]"
Records file snapshots permanently in the version history.
git diff [first-branch]...[second-branch]
Shows content differences between two branches.
Redo commits
git reset [commit]
Undoes all commits after [commit], preserving changes locally.
git reset --hard [commit]
Discards all history and changes back to the specified commit.