5 essential commands to interact with an online git repository: push, pull, clone, fetch, remote (video)

5 essential commands to interact with an online git repository: push, pull, clone, fetch, remote (video)

Last Updated on Nov 27, 2022

https://youtu.be/K6THyJKayFo

 

Transcription

Hello

This is amir

Today we are going to talk about 5 commands you need to know to interact with and online git repository

So let’s get started

Prepare the online git repository

Here I create an online repository on github

It gives me the url of this repo

And it also gives me some instruction on how to sync the repository with the local project

Now let’s start with our 5 commands

First Command: Git Remote

The first one is “Git remote

Remotes are the online repositories that you track.

if your project is local and you want to upload it online then you should set a remote address

In order to add a new remote

you just need to run this command

Git remote add name url

The default name for most of the online repositories is origin

So here we also name our remote origin

And as for url, At this moment even if you write a random url like google.com it’s not going to give you an error but later when you want to update the local repo with the online repo it will give you an error because the online url you’ve provided is not a git repository

Ok let me create a new file and commit the changes

If we run

git remote -v

We can see the list of remotes and their url

great

Second Command: Git Push

The next command we are going to talk about is “git push

It’s like uploading all your local updates to the online repository

Git push name-of-remote branch-you-want-to-push

Here i’m sending the master branch

In github the master branch is sometimes called main branch

Here I am already signed in with github and github knows that I’m the owner of the repository otherwise you can’t just push to the master branch of repositories that you are not the owner

Let me create a new branch to show you what would happen when you push a new branch

This would be similar to when you push to another person’s repository

When I push the new branch This will create a branch in the online repository and then in the online repository

You can make a pull request

And then merge it or not
Third Command: Git Fetch

The next command we are going to talk about is “git fetch”

This one downloads all the new updates from the online repository to your local repository but doesn’t merge them

Afterwards You should merge them yourself

Here let me add the origin and let’s run git fetch

Now as you can see there is no file in my local repo

And if I run

git branch

it doesn’t show any branches

After a git fetch if you want to see the branches you should run the git branch command with flag r

git branch -r

And now you can see the list of downloaded branch

It’s time for you to go and merge them with your local repository

By running

Git merge origin/branch-name

Which here is master

Now you can see all the files in the local repository as well.

Fourth Command: Git Pull

The next command we are going to talk about is “git pull

It’s like git fetch but it also merges the new updates

it’s like running the command Git fetch and git merge together

Here I initialize a new git repository and add the remote

Then when we run the command

git pull

you can see all the files in the master branch

Fifth Command: Git Clone

The last command we are going to talk about is “git clone

It’s like completely downloading a git project to your computer

To do that we run the command

Git clone url

We don’t need to initialize a git repository first

Here it created a new folder with the repository name and if i go inside it i can see the files

Also if I run

git remote -v

I can see that it has automatically added the remotes as well

And when I run git branch with flag r

git branch -r

It shows me all the branches as well

Let’s see if i can add a new file to our online repository

And yes I can.

Perfect

Key Takeaways

Just a quick recap:

  • We talked about the 5 commands that you need to know in order to interact with an online repository
  • Git remote to add the url of an online repo
  • Git fetch to download the data from the online repo but it doesn’t merge it
  • Git pull to download the data from online repo and merge them
  • Git push to upload the data to the online repo
  • Git clone to download the whole repository

Final Words

And finally

if you liked what you learned please like and subscribe

That would be a great motivation to do more videos

If you have any suggestions or questions please leave a comment below and I try to answer them as soon as possible

That’s it

Have a wonderful day.

Link to Video:

You can watch the original video on youtube.

 

Category: programming

Tags: #git #open source

Join the Newsletter

Subscribe to get my latest content by email.

I won't send you spam. Unsubscribe at any time.

Related Posts

Courses