git – what is origin

I have started learning git ( which is very famous and widely used tool for code repository and version control ).

Basic commands which I use normally are ::
1. git clone URL – this is to clone the repo
2. git pull – to pull the content from repo
3. git branch – It tells which branch you are on, and of course to change the branch
4. git add, git commit and git push – to add, commit and push the local changes to git.

Now, there is a command which I am using lately to push my changes to git for review::
git push origin HEAD:refs/for/RHEL71 –

And, I had this question, what is origin in this command? I had different answers from different people. But nothing satisfied me. After some more reading this the conclusion::

ORIGIN – origin is the alias of remote git repo which we have cloned. It is not the NAME of remote repository infect, it is an ALIAS given to the URL which points to the default remote repository.

There can be multiple repos cloned, and you can see what url belongs to each remote by using ::
git remote -v

While pushing, you can use remotes or you can simply use a url directly ::
git push git@github.com:git/git.git master

You can see more info about the remote by typing ::
git remote show origin

And interestingly, you can change this alias anytime you want using ::
git remote rename origin anotherAliasNameForTheRepoUrl

Since, I am in learning phase and there will be many more things which I would like to explore, you can expect more post on git from me 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s