Basic Operations in Git
In my previous articles, I have covered An intro to Git and Github and How to Push a Project to GitHub. Today we will learn about the basic operations of git. There are almost five basic operations in Git.
If you have followed my previous articles, you might have an idea about these operations. Let’s discuss them but before that, if you don’t know about Git then do read my article on “An intro to Git and Github” first and then continue with this article. If you have the know-how of git. Let’s continue.
Initializing in Git is used to convert a simple folder to a Git repository. To initialize the folder as a Git repo you need to navigate the folder which you want to be initialized as git and start the Git terminal and run the command given below.
Now, your folder is initialized as a Git repo and it will have a folder named “.git”, it may not be visible but you can see if you change the setting to “show hidden folders”. The initialized repo is also known as the “Working directory”.
The root folder of your project is often called the “Working copy” or “Working director”. It is the directory on your local computer that contains your project’s files.
The Add operation is used to adds a change in the working directory to the staging area. A staging area is a virtual place that collects all the files you want to include in the next commit.
It Git add operation tells the git that you want the updates of a particular file, included in the next commit. However, add operation doesn’t really affect the repository in any way and changes are not actually recorded until you commit the code. Add operation is performed using
git add <filename> (for specific file)
git add -a (for all files)
Commit operation in git is used to save all changes present in the staging area along with a short description from the user in a local repository. Commits are very much important in Git. You can think of every commit as a snapshot of your project, where a new version of that project is created in the current repository. Git commit is performed using
git commit -m “user message”
The pull operation is used to fetch and download data from a remote repository and merge it into the local repository to match that code or data. Git pull is performed using
Push operation is used to upload local repository data to a remote repository. Git push is performed using
git push origin main
Now, you know about the basic operation of git. In the next article, we will focus on advance Git operations. Don’t forget to share, if you find out helpful.