Git is a distributed version control system that allows you to track changes to files and coordinate work on those files among multiple people. It was created by Linus Torvalds in 2005 to manage the development of the Linux kernel, but it has since become one of the most widely used version control systems in the world.
With Git, you can keep a record of who made changes to what part of a file, and you can revert back to earlier versions of the file if needed. Git also makes it easy to collaborate with others, as you can share changes and merge the changes made by different people into a single version of a file.
GitHub, on the other hand, is a web-based platform that provides hosting for version control using Git. It was created in 2008 and is now a subsidiary of Microsoft. GitHub offers all of the distributed version control and source code management (SCM) functionality of Git, as well as adding its own features.
GitHub is a very popular platform for developers to share and collaborate on projects, and it is also used for hosting open-source projects. In addition to hosting Git repositories, GitHub provides features like issue tracking, project management, code review, and more.
Now that we have a basic understanding of Git and GitHub, let's walk through the steps of creating a new repository on GitHub, cloning it to your local machine, making changes to a file, and committing and pushing those changes back to GitHub.
Before we get started, make sure you have Git installed on your computer and that you have created a free account on GitHub. If you haven't done so already, you can download Git from the official website at git-scm.com/downloads and sign up for a free account on GitHub at github.com.
Step 1: Create a new repository on GitHub
To create a new repository on GitHub, follow these steps:
Log in to your GitHub account.
Click on the "+" icon in the top right corner of the screen and select "New repository."
Give your repository a name and description.
Choose whether you want your repository to be public or private.
Click "Create repository."
Your new repository should now be created on GitHub.
Step 2: Clone the repository to your local machine
To clone the repository to your local machine, follow these steps:
Go to your new repository on GitHub.
Click on the green "Code" button.
Copy the URL provided.
Open your terminal and navigate to the directory where you want to store your repository.
Type "git clone" followed by the URL you just copied.
For example, if your repository URL is github.com/username/my-repo.git, you would type:
git clone https://github.com/username/my-repo.git
This will create a new directory on your local machine with the contents of your repository.
Step 3: Make changes to a file
After you have cloned the repository to your local machine, you can make changes to the files in the repository. For example, you might want to add a new file, edit an existing file, or delete a file.
To make changes to a file, open the file in a text editor or other program, make your changes, and save the file.
Step 4: Commit your changes
Once you have made changes to a file, you need to commit those changes to the repository using Git. To do this, open a command prompt or terminal window, navigate to the directory where the repository is located, and use the following commands:
git add .
git commit -m "Your commit message here"
The first command adds all of the changes you have made to the repository to the Git staging area. The second command commits those changes to the repository, along with a message that describes the changes you have made.
Step 5: Push your changes to GitHub
After you have committed your changes to the repository, you need to push those changes back to the repository on GitHub. To do this, use the following command:
git push
This command pushes all of your committed changes to the remote repository on GitHub.
Conclusion
Using Git and GitHub can seem daunting at first, but it is an essential skill for anyone who wants to work on software development projects or other collaborative projects. By creating a new repository on GitHub, cloning it to your local machine, making changes to a file in the repository, and committing and pushing those changes back to the repository using Git, you can collaborate with others and keep track of changes to your project over time.
Happy Learning ๐
Bhaktiben Kadiya