What is origin in git commands?

2 min read
Important Keywords To Understand

remote
remote refers to a git repository that is hosted on the internet ( i.e Github, Bitbucket, etc )


local
local refers to a git repository that is on your laptop after cloning any remote repository.

Now let's clone a repository

Command to clone: git clone url_of_repository

Example

Now let's add a new file in this repo from local.

Now let's push the changes to the remote that we have done in the local repo.

Example

we have used the command i.e

git add . It tells Git that you want to include all changes of the current directory in the next commit. 
git commit -m message This command will commit the changes and generate a commit-id.
git push origin master It will push all the committed changes from the local repository to remote repository in the master branch.

Now if you do git remote -v then it will show the output like this: 


This means git has stored the short name of the original repository URL as origin. You can consider it as a key value pair where the origin is key and the URL is the value that is mapped to the key.

Key: origin
Value: https://github.com/cenation092/InterviewBit-Solutions.git

Now we know the value of origin so let's do an experiment
Let's replace the origin from git push origin master with the value of origin and see what will happen.


Voila!! It again pushed the changes from the local repository to remote repository in the master branch.

Now we can clearly understand the git push command.

git push url_of_the_remote_repository branch_name_of_the_remote_repository
Example: git push https://github.com/cenation092/InterviewBit-Solutions.git master
or 
git push short_name_of_the_url_of_remote_repo branch_name_of_the_remote_repository
Example: git push origin master

Note: we can change the short name of the URL of a remote repository. Origin is the by default short name of the URL of a remote repository that we clone.

Like this: 


Thank You 🙂

3 comments:

Powered by Blogger.