Day 8/90 - #90daysofdevops
What is Git? ๐
Git is a version control system that allows you to track changes to files and coordinate work on those files among multiple people. It's commonly used for software development, but it can be used to track changes to any set of files. ๐๐ป
With Git, you can keep a record of who made changes to what part of a file, and you can revert 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. ๐โจ
What is GitHub? ๐๐ฅ
GitHub is a web-based platform that provides hosting for version control using Git. It's a subsidiary of Microsoft, and it offers all of the distributed version control and source code management (SCM) functionality of Git, as well as adding its features. GitHub is a very popular platform for developers to share and collaborate on projects, and it's also used for hosting open-source projects. ๐๐๏ธ
What is Version Control? How many types of version controls do we have? ๐
Version control is a system that tracks changes to a file or set of files over time so that you can recall specific versions later. It allows you to revert files back to a previous state, compare changes over time, see who last modified something that might be causing a problem, and more. ๐๐
There are two main types of version control systems: centralized version control systems and distributed version control systems. ๐๐
๐ข Centralized Version Control System (CVCS) ๐ข In a CVCS, developers "check out" files from a central server, make changes, and then "check in" the updated files. Examples include Subversion and Perforce. ๐ฉ๐
๐ Distributed Version Control System (DVCS) ๐ In a DVCS, developers "clone" an entire repository, including the entire version history of the project. This means they have a complete local copy of the repository, making collaboration easier and improving speed and flexibility. Examples include Git, Mercurial, and Darcs. ๐๐
Why Use Distributed Version Control Over Centralized Version Control? ๐ช
Better Collaboration: In a DVCS, every developer has a full copy of the repository, enabling easier collaboration without constant communication with a central server.
Improved Speed: With a local repository, developers can commit changes faster, no longer relying on constant server communication.
Greater Flexibility: DVCS allows offline work and selective sharing of changes with subsets of the team.
Enhanced Security: The distributed nature of DVCS provides resilience against data loss.
Overall, the decentralized nature of DVCS offers greater collaboration, flexibility, and security, making it a popular choice for many teams. ๐๐ค
Ready to embark on your version control journey? Let's Git started! ๐ป๐ฒ #Git #GitHub #VersionControl #DevOpsEnthusiast #TechJourney
Git installation and account creation :
Install Git on your computer (if it is not already installed). You can download it from the official website at git-scm.com/downloads
Create a free account on GitHub (if you don't already have one). You can sign up at github.com
Learn the basics of Git by reading through the video This will give you an understanding of what Git is, how it works, and how to use it to track changes to files.
Creating new repo/cloning repo/push & commit :
(A) Create a new repository on GitHub and clone it to your local machine
Step 1: Create a new repository on GitHub
Go to github.com and log in to your GitHub account (or sign up if you don't have one).
Click on the "+" button at the top right corner of the page and select "New repository" from the dropdown menu.
On the "Create a new repository" page, enter a name for your repository. Choose a name that is descriptive and meaningful for your project.
You can also provide an optional description for your repository to explain what it's about.
Choose the repository's visibility (public or private) based on your needs and GitHub account type.
If you want to add a README file, .gitignore, or license, you can select the options accordingly.
Once you've filled in the required details, click on the "Create repository" button to create the new repository on GitHub.
Step 2: Clone the repository to your local machine After creating the repository on GitHub, you can clone it to your local machine using the following steps:
Open a terminal or command prompt on your local machine.
Change the current working directory to where you want to clone the repository. For example, if you want to clone it to your Desktop, you can use the command:
cd ~/Desktop
Find the repository's URL on GitHub. Click on the "Code" button on your repository's page and copy the HTTPS or SSH URL.
Run the following command in the terminal to clone the repository to your local machine:
git clone <repository_url>
Replace <repository_url>
with the URL you copied from GitHub. For example, if you're using HTTPS, the command would look like:
git clone https://github.com/yourusername/your-repository.git
- You might be prompted to enter your GitHub credentials if you're using HTTPS as the repository URL.
That's it! The repository should now be cloned to your local machine, and you can start working on it locally and push changes back to GitHub when you're ready.
(B) Make some changes to a file in the repository and commit them to the repository using Git
Assuming you have already cloned the repository to your local machine (if not, please refer to the previous point on how to clone a repository), follow these steps:
Navigate to the repository: Open a terminal or command prompt and change the current working directory to your local repository on your machine. For example, if your repository is located on the Desktop, you can use:
cd ~/Desktop/your-repository
Make changes to the file: Use your preferred text editor or code editor to make the necessary changes to the file you want to modify. For example, if you want to modify a file named "example.txt," open it in your editor, make the changes, and save the file.
Check the status of the repository: It's a good practice to check the status of your repository to see which files have been modified. Use the following command:
git status
This will display a list of modified files.
Add the changes to the staging area: To include the changes you made to the file in the next commit, you need to add them to the staging area. Use the following command:
git add path/to/modified-file
If you modified "example.txt" in the root directory of the repository, the command would be:
git add example.txt
You can also use a period (
.
) to add all modified files to the staging area:git add .
Commit the changes: After adding the changes to the staging area, you can commit them with a commit message that briefly describes the changes you made. Use the following command:
git commit -m "Your commit message here"
Replace
"Your commit message here"
with a meaningful message that explains the changes, you made in the commit.Push the changes (if using a remote repository): If your repository is connected to a remote repository (e.g., GitHub), and you want to sync your local changes with the remote repository, use the following command:
git push origin master
This command will push your changes to the "master" branch on the remote repository. Replace "master" with the name of the branch you want to push to, if different.
Now your changes are committed to the Git repository. The commit history will reflect your changes, and others can access them if you've pushed the changes to a remote repository.
(C) Push the changes back to the repository on GitHub
To push the changes back to the repository on GitHub, you'll need to use the git push
command. Assuming you've already made changes and committed them locally (as explained in the above point), here are the steps to push those changes to the remote repository on GitHub:
Check the remote repository URL: Open a terminal or command prompt and navigate to your local repository's directory (if you're not already there). Use the following command to view the remote repository's URL:
git remote -v
This command will display the fetch and push URLs of the remote repository.
Push the changes to the remote repository: Use the following command to push your local changes to the remote repository on GitHub:
git push origin master
Here,
origin
refers to the remote repository's name (usually set as "origin" by default when you clone the repository). If you have multiple remotes, you might need to specify the appropriate remote name instead of "origin." Themaster
part refers to the branch you're pushing the changes to. Replace "master" with the name of the branch you want to push to if you're using a different branch.If you're pushing to a different branch, the command would look like this:
git push origin your-branch-name
Enter your GitHub credentials (if prompted): When you run the
git push
command, Git might prompt you to enter your GitHub username and password (for HTTPS URLs) or your SSH passphrase (for SSH URLs) to authenticate your push. If you're using HTTPS and don't want to enter your credentials every time, you can set up Git credential caching.Verify the changes on GitHub: After successfully pushing the changes, go to your GitHub repository's page. You should see the changes reflected in the repository's history and files.
Hope this blog was useful for the basic topic understanding of Git and GitHub. Keep learning, keep practicing :)