ProDeveloperTutorial.com

Tutorials and Programming Solutions
Menu
  • Shell Scripting
  • System Design
  • Linux System Programming
  • 4g LTE
  • Coding questions
  • C
  • C++
  • DSA
  • GIT
  • 450 DSA Cracker
  • 5G NR
  • O-RAN

Chapter 7: GIT Collaboration Commands

prodevelopertutorial August 3, 2020

In this chapter we shall learn about below git commands:

git fetch
git pull
git remote
git submodule

git fetch

* “git fetch” command is used to pull the latest changes from the remote repository to your local repository.

* It will not merge with your changes. Hence your working repository will remain safe from merge conflicts.

* You will use “git fetch” to know the snapshot what others are working on.

Example:

To fetch a remote repository use:

“git fetch <remote_repository_url>”

git fetch

git pull

* “git pull” is used to pull a remote repository.

* If you have made changes in local repo and do a “git pull”, then the latest changes will be merged.

* So there might be changes of merge conflict.

* But if you are working on a repository and need to check other commit, then “git fetch” is a safe option.

* Ideally “git pull” = “git fetch” + “git merge”

Example:

To pull a remote repository use:

“git pull <remote_repository_url>”

git remote

* GIT is very much different from SVN. In SVN, you will have a single repository and you will be committing those changes in that single repository.

* But in GIT, every developer will be having their own local repository. Each developer will make changes in their repository and then push to the remote repository.

* The following operations are performed on remote repository “clone, fetch, push, pull”.

* “git remote” is used to add, view, delete connections to remote repository

Now let us see how to perform “git remote” and related operations in series of examples:

1. To add a remote repository use “git add <name> <repo_url>”

git repo add algorithms_repo https://github.com/trekhleb/javascript-algorithms.git

git remote

2. To know the remote repository, use “git remove -v”

git remote

3. To fetch remote repository, use “git fetch <repo_name>”. RepoName should be the name that you used to save the repo url.

git remote

4. To remove a remote repo, use “git remote rm <repo_name>”

git submodule
—————-

* Sometimes, in a project, you will need to include the code of another project.

* Inclusion can be done in many different ways, for example, download the code and include the code directly into your project.

* But one definite downside is, if there are any update to that project’s code, your project will be missing that.

* In such case, you will need to use “git submodule” command. This command will create a link to the other project code, so it will get updated automatically whenever there is an updated to other project code.

* For example, you need to use openSSL security library in your project, so you will create a link to that project in your project with “git submodule” command.

In below example, I have created a submodule link to openSSL repository by using below command:

git submodule add https://github.com/openssl/openssl.git

git_submoduleimage 40

git push
—————-

“git push” command is used to push the local changes to remove repository.

Syntax:
git push <repo name> <branch name>

Example:
——–
git push origin master

 

 

Share
Email
Tweet
Linkedin
Reddit
Stumble
Pinterest
Prev Article
Next Article

About The Author

prodevelopertutorial

Follow this blog to learn more about C, C++, Linux, Competitive Programming concepts, Data Structures.

ProDeveloperTutorial.com

Tutorials and Programming Solutions
Copyright © 2022 ProDeveloperTutorial.com