Table of Contents
Git is a distributed version control system used for managing source code and files in software development projects. Here are the key features of Git:
- Version Control: Git allows recording different versions (commits) of the project, providing a version history.
- Distributed System: Each user has a complete copy of the project. This facilitates independent work and branching.
- Branching and Merging: Users can create separate branches for adding new features or fixing bugs and merge these branches back into the main project.
- Tracking and Reverting: Easily track changes, revert modifications, or roll back to previous versions.
- Collaboration: Multiple developers can work on the same project and share changes.
- Lightweight Tagging: Adding tags to the project to mark specific versions.
- GitHub, GitLab, Bitbucket Integration: Platforms integrated with Git for online storage and collaboration.
- Performance: Git operates efficiently, providing quick performance.
Git is widely used, especially in open-source software development projects.
Installing Git
For Windows Operating System:
- Visit the official Git website: Git Downloads.
- On the download page, select the version suitable for Windows and download it.
- Run the downloaded file to start the installation wizard.
- Follow the wizard steps to install Git on your computer. Default options are usually acceptable.
- Once the installation is complete, you can use tools like Git Bash and Git GUI.
For macOS Operating System:
- Visit the official Git website: Git Downloads.
- Download the version suitable for macOS.
- Open the downloaded file and follow the installation wizard.
- During the installation, select “Command Line Tools” to continue.
- Once the installation is complete, you can use Git via Terminal or Git GUI.
For Linux Operating System:
Debian/Ubuntu-Based Distributions (Using apt Package Management):
sudo apt update
sudo apt install git
Red Hat/Fedora/CentOS-Based Distributions (Using yum or dnf Package Management):
sudo yum install git
or
sudo dnf install git
For Other Linux Distributions:
Git is available in the repositories of many Linux distributions. You can install Git using the specific package management of your distribution.
To verify the installation, open a terminal or command prompt and type git --version
to check if Git is installed.
Git Cheat Sheet:
Configuring Git:
- Set user name:
git config --global user.name "Your Name"
- Set user email:
git config --global user.email "your.email@example.com"
Creating Repositories:
- Initialize a new repository:
git init
- Clone a repository:
git clone repository_url
Making Changes:
- Check status:
git status
- Stage changes:
git add filename
- Commit changes:
git commit -m "Commit message"
Branching:
- Create a new branch:
git branch branch_name
- Switch to a branch:
git checkout branch_name
- Merge branches:
git merge branch_name
- Delete a branch:
git branch -d branch_name
Remote Repositories:
- Add a remote repository:
git remote add origin repository_url
- Push to a remote repository:
git push -u origin branch_name
- Pull from a remote repository:
git pull origin branch_name
Undoing Changes:
- Discard changes in working directory:
git checkout -- filename
- Undo last commit:
git reset HEAD~1 --soft
Viewing History:
- View commit history:
git log
- View changes in a commit:
git show commit_hash
- View differences:
git diff
Tagging:
- Create annotated tag:
git tag -a tag_name -m "Tag message"
- Push tags to remote repository:
git push --tags
This cheat sheet provides quick references for common Git commands. Customize commands based on your specific use case.