Git is a popular DevOps tool used for source code management. It is one of the most popular version control systems today that is widely used to handle all sizes of projects effectively and efficiently. It helps in tracking changes in the source code, allowing different people to work on different parts of the same program. Git is a recognized approach to contribute to a project collaboratively.
Let us now begin this Git pull request tutorial with an overview of Git.
What is Git?
Git is a version control system for monitoring the changes in computer files. It is used to collaborate with several people on a project and track progress throughout the project. Whenever a developer wishes to start working on something, a new branch is created, to ensure that the master branch always has a production-quality code.
Git is not just for programmers or developers; it also helps non-technical users track their project files efficiently. It allows all the team members to be on the same page of the project, which plays a significant role while working on a large project that involves a large number of people.
Next, in this Git pull request tutorial, let us learn about GitHub.
What is GitHub?
GitHub is a website based service that is used by developers all over the world to store and share their code with other developers. Git repository hosting service provides a web-based graphical interface, unlike Git. GitHub helps all the team members to work together on the project from anywhere. The team members can access files and easily merge changes with the master branch of the project.
GitHub is one place where project managers and developers coordinate, monitor, and update their work, so there is transparency in the project, and it stays on schedule. The packages can be published privately, or within the team or publicly for the open-source community.
Different Git Commands
There are several commands used in Git like:
1. Git config
2. Git init
3. Git add
4. Git diff
5. Git commit
6. Git reset
7. Git status
8. Git merge
9. Git push
10. Git pull
After having looked at the different commands in Git, let us extend our learning of the Git pull request tutorial by looking at Git pull in detail.
Git Pull
The git pull command is used to retrieve and download content from a remote repository and update the local repository as soon as it has been downloaded. In Git-based collaboration workflows, it is common to merge remote upstream changes into your local repository.
The Git pull command is used to fetch and merge code changes from the remote repository to the local repository. Git pull is a combination of two commands, Git fetch followed by Git merge.
In the first stage, Git fetch is executed that downloads content from the required remote repository. Then, the Git merge command combines multiple sequences of commits into a single branch.
Git Pull Demo
Let’s begin with making a directory.
mkdir Git_Demo cd Git_Demo pwd |
The directory. as of now, is empty.
Let’s create a folder for the repository.
mkdir Changes cd Changes pwd |
The folder “Changes” is empty. We will now initialize a repository to our folder.
Git init |
Now something called the “master” appears on the screen. Whenever a Git repository is created for the first time, it creates a branch. The name of the branch is master, and that is why we see master on the screen.
Navigate to the folder to find a hidden “.Git” folder.
This is created when a repository is initialized.
If you go on to check the folder, you can see a bunch of directories and configurations. Make sure you don't make any changes to any of the directories.
Next, let's pull our files from the remote repository (GitHub).
For that, go to your GitHub, go to the repository and then to the clone or download option, and copy the URL.
Coming back to GitHub, paste the URL with Git pull command.
Git pull *clone or download URL* |
All the contents from the repository have been pulled to our local repository.
The contents can be found in the desired directory.
Now, let's make changes in the pulled files, and later push them back on the GitHub.
Come back to Git bash, open the notepad, and edit the contents.
C:/windows/notepad alpha |
Save it and close it.
Open the next notepad.
C:/windows/notepad alpha |
Save it and close it.
Next is to check the status of all the files and directories.
Git status |
It shows that no file is yet committed, and there are untracked files. The untracked files can be seen in red color.
For Git to track that file, the add command is given. If you know the exact name of the file, you can specify that simply type the following command:
Git add . |
After add, the next step is to commit these files.
Git commit -m “changes made” |
Let’s check the status of the file again.
Git status |
It can be seen that there are no more commits to be made. After the commits are made, let’s push the edited files back to the remote repository.
Again go back to your GitHub and copy the URL.
Come back to Git bash, type the Git remote command and paste the URL.
Git remote add origin *URL* |
Git remote -v |
Now let's push the content back on to the remote repository.
Git push -u origin master |
The edited content has been sent back to the remote repository. Let’s go and check the content there.
The contents of the notepad can be seen, and it is evident that the content has been changed. The commit “changes made” may also be seen.
Enroll in Post Graduate Program In DevOps and learn to work on tools like Docker, Git, Jenkins, Puppet & Nagios.
Conclusion
In this Git pull request tutorial, you have learned the basics of the pull command and also seen a hands-on demo of the same. In the Git pull demo, we saw how files from the remote repository could be pulled to the local repository. Then after making the changes to them how they can be sent back to GitHub. The process makes it possible for anyone to access the content and make commits to the same.