Git Cheat Sheet
Git is a distributed version control system that supports collaboration through teams in the corporation. Teams of developers and open-source software maintainers basically handle and manage their projects through Git. It is very useful as open-source software toolkit for developers and DevOps engineers.
Git is ready to download it from the official website and is available for Linux, MacOS and Windows.
Check your Git version with the following command.
Initialize the current working directory as a Git repository with the following command.
Clone your projects from hosted remotely Git repositories with specified repo's URL or server location on GitHub or GitLab instances.
git clone https://www.github.com/username/repo-name
Show your current Git directory's remote repository.
Check the status of your Git repo including files added that are not staged and the files that are staged also.
Include all the available files in the current working directory.
git add .
Remove a file from staging within your working directory.
git reset CDI.java
Commit the staged files with meaningful commit message that you can track your commits later on.
git commit -m "Added new files"
Show all available current branches with the following command.
Create a new branch on your working directory.
git branch new-branch
Switch to another existing branch and checkout to your current working directory.
git checkout another-branch
Create the branch and switch to the new one to your current working directory.
git checkout -b new-branch
Merge the specific branch's history into the current one's.
git merge branch-name
Collaborate and Update
Fetch and merge any commits from the tracking remote branch.
Push your local branch commits to the remote repository branch.
git push origin main
Display the commit history for the currently active branch.