Table of Contents
How to use the git command every day. Git Cheat Sheet I use it every day. Git has become an essential tool for developers, allowing them to efficiently manage version control and collaborate on projects.
this guide will provide you with a comprehensive overview of Git’s essential commands and workflow. Let’s dive in!
What does Git mean?
Git is software for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. Quote from Wikipedia.
Git Cheat Sheet Example
Check my git configure
git config -l
Before you start using Git, it’s crucial to set up your configuration. You can configure your username and email globally using the
git config command. For example Setup my Git username and Email Id
git config --global user.name "HuuPV"
git config --global user.email "HuuPV@devopsroles.com"
Username and EmailID assigned to commit from local computer.
Creating and Cloning Repositories
Add a file to the staging area in Git
git add file_name
Add all files in your project to the staging area in Git
git add .
Commit changes for the files in a local repo.
git commit -m "first commit"
Shows the commit history for the current repository
Show if a file is in the staging area, but not committed
Remove tracked files from the current working tree
git rm filename
git mv oldfile newfile
Branches are a powerful feature in Git, allowing you to work on different versions of your code simultaneously.
Create a new branch
git branch branch_name
Switch to a newly created branch
git checkout branch_name
Create a new branch and switch it immediately
git checkout -b branch_name
Merge and Remote Repositories
Merge two branches
git merge branch_name
Add a remote repository to your local repository
git add remote https://repo_url_here
download updates from a remote repository.
After committing your changes, the next you send changes to the remote server.
git push #or force push git push -f
History and Logs
Git provides extensive tools to explore commit history. The
git log the command shows the commit history
The display presents a more compact view
git log --oneline
If you prefer a graphical representation,
git log --graph creates a commit history graph.
git log --graph
To view the details of a specific commit
git show <commit>
Git is a powerful version control system that enables efficient collaboration and project management. This guide has provided an overview of essential Git commands and workflows, giving you a solid foundation to start using Git effectively
You have used Git Cheat Sheet every day. I hope will this your helpful. Thank you for reading the DevopsRoles page!