5 essential commands to interact with an online git repository: push, pull, clone, fetch, remote (video)
Last Updated on Nov 27, 2022
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
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
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
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
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
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
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
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
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
I can see that it has automatically added the remotes as well
And when I run git branch with flag 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.