Day 05 - Git Basic Commands
Introduction
Git is a popular version control system used by developers to manage their source code. It was created by Linus Torvalds in 2005 to help maintain the Linux kernel. Since then, it has become one of the most widely used version control systems in the world, with developers and companies relying on it to manage their codebases. In this blog post, we will discuss the basics commands of Git and how to get started with it.
Creating a Git Repository
Before we can start using Git, we need to create a Git repository. A Git repository is a directory where Git will store all the versions of your source code. To create a new Git repository, navigate to the directory where you want to store your code and run the following command:
git init
This will create a new Git repository in the current directory.
Once you have a Git repository, you can start adding and committing changes to it. To add a file to the repository, use the following command:
Recommended by LinkedIn
git add <file_name>
This will add the file to the staging area, which is where Git tracks changes that you want to commit. Once you have added all the files that you want to commit, you can commit them using the following command:
git commit -m "Commit message"
This will create a new commit with the changes you have made. It is important to add a descriptive commit message that explains what changes you have made.
Pushing to remote repository
The git push command is used to transfer or push the commit, which is made on a local branch in your computer to a remote repository like GitHub. The command used for pushing to remote repository is given below.
git push 'remote_name' 'branch_name'
Conclusion
Git is a powerful tool that is essential for any developer who wants to manage their source code effectively. In this blog post, we have covered the basic commands of Git, including creating a repository, adding and committing changes, and pushing code to remote repository. With these tools, you can manage your codebase