A Git CLI cheat-sheet
Hello, amazing people 👋
I am finally back in 🍁and after a 20 hour flight, I needed some time to relax and get back to my EST time zone schedule.
This week I had some fun with cleaning up my Github, while I was doing that I realized why not create a Git CLI cheat sheet to help other.
Now, let me get started with Git.
What is Git?
Git is a free, open-source version control software. It was made by Linus Torvalds in 2005. This tool is a version control system that was at first evolved to work with a few engineers on the Linux Kernel.
This basically means that Git is a content tracker. So Git can be used to store content — and it is mostly used to store code because of the other features it provides.
Real life projects generally have multiple developers working in parallel. So they need a version control system like Git to ensure that there are no code clashes between them.
The branch system in Git permits developers to work independently on an undertaking (For instance: One branch - > One errand OR One branch - > One developer). Fundamentally consider Git a little programming application that controls your code base, in case you're a developer.
So to begin utilizing Git, we need to realize where to have our repositories.
A repository (or "Repo" for short) is a task that contains numerous documents. For our situation a repository will contain code-based records.
There are two different ways you can have your repositories. One is on the web (on the cloud) and the second is not on web (self-hosted).
There are three well known hosting services: GitHub, GitLab and BitBucket.
I would like to share this amazing article 'The Beginners Guide to Git' by Thanoshan MV.
Now let's get to the the cli commands.
Some Git CLI commands
Git : Configure
git config --global user.email "email@example.com "sets email address respectively to be used with your commits.
git config --global user.name "FirstName LastName"sets the author name.
git config --listcommand to list all the settings Git can find at that point.
git config --global color.ui trueGit automatically colors of its output.
Git : commit to repository
git commit -m "Add three files"command records or snapshots the file permanently in the version history.
git commit --amend -m <enter your message>command allows you to change the commit message.
Git : branching
git branchcommand lists all the local branches in the current repository.
git branch <branch-name>command creates a new branch.
git checkout <branch-name>command is used to switch from one branch to another.
git merge <branch-name>command merges the specified branch’s history into the current branch.
git checkout -b <branch-name>command creates a new branch and also switches to it.
Git : Initiating a repository
git initcommand is used to start a new repository.
git statuscommand lists all the files that have to be committed.
Git : Pulling & pushing from and to repositories
git remote add origin <link-to-repo>ommand is used to connect your local repository to the remote server.
git push -u origin maincommand sends the committed changes of main branch to your remote repository.
git clone <link-to-clone-repo>command is used to obtain a repository from an existing URL.
git pullcommand fetches and merges changes on the remote server to your working directory.
Git : Staging
git add <file-name>command adds a file to the staging area.
git add <file-name> <second-file-name> <third-file-name>command adds one or more files to the staging area.
git add .command adds all files under the current directory to the staging area.
git add --allcommand finds all new and updated files everywhere throughout the project and add them to the staging area.
git add -ASame as
git rm --cached <file-name>
git reset <file-name>command unstages the file, but it preserves the file contents
The PDF version of the same is available here.
Hope this is helpful, and if you have any concerns or feedback feel free to reach out on Twitter, my dms are open 🙂.