December 5, 2019
December 5, 2019
Need to learn some basic GIT commands? You’ve come to the right place. Read on to discover our handy cheat sheet that you can use for daily reference.
Let’s get started!
GIT is the most widely used open-source VCS (version control system) that allows you to track changes made to files. Companies and programmers usually use GIT to collaborate on developing software and applications.
A GIT project consists of three major sections: the working directory, the staging area, and the git directory.
The working directory is where you add, delete, and edit the files. Then, the changes are staged (indexed) in the staging area. After you commit your changes, the snapshot of the changes will be saved into the git directory.
Here are some basic GIT commands you need to know:
Alternatively, you can create a repository within a new directory by specifying the project name:
git init [project name]
git clone username@host:/path/to/repository
Conversely, run the following basic Git command to copy a local repository:
git clone /path/to/repository
git add <temp.txt>
git commit –m “Message to go with the commit here”
Note that any committed changes won’t make their way to the remote repository.
git config --global user.email firstname.lastname@example.org
The –global flag tells GIT that you’re going to use that email for all local repositories. If you want to use different emails for different repositories, use the command below:
git config --local user.email email@example.com
git push origin <master>
Replace <master> with the branch where you want to push your changes.
command git checkout -b <branch-name>
To switch from one branch to another, simply use:
git checkout <branch-name>
git remote –v
To connect the local repository to a remote server, use the command below:
git remote add origin <host-or-remoteURL>
Meanwhile, the following command will delete a connection to a specified remote repository:
git remote rm <name-of-the-repository>
If you want to delete a branch, use:
git branch –d <branch-name>
git merge <branch-name>
git diff --base <file-name>
The following basic Git command is used to view the conflicts between branches before merging them:
git diff <source-branch> <target-branch>
To list down all the present conflicts, use:
git tag <insert-commitID-here>
commit 15f4b6c44b3c8344caasdac9e4be13246e21sadw Author: Alex Hunter <firstname.lastname@example.org> Date: Mon Oct 1 12:56:29 2016 -0600
git reset --hard HEAD
git rm filename.txt
git fetch origin
git ls-tree HEAD
git cat-file –p d670460b4b4aece5915caf5c68d12f560a9fe3e4
git grep "www.hostinger.com"
git instaweb –httpd=webrick
git archive --format=tar master
git rebase master
If you are just starting out with GIT, it can be hard to remember even the basic commands. For that reason, we’ve put together a GIT cheat sheet to help you master the software. Save the file to your devices or print it out so you’ll always have it ready when you’re stuck.
Learning basic GIT commands will go a long way for developers as they can easily control the projects’ source code. It might take some time to remember all of them, but hopefully, our GIT cheat sheet will be helpful for you.
Practice those commands and make the most of your developing skills! Good luck!
September 12 2019