- You need a Github account.
- You need to create a repository and get the URL of the repository. There are two types of URL https and ssh. For this demo we will use https.
Example : https://github.com/tyson332/DemoRepository.git
- Now we need to add the above remote URL into git and give it a name, command to do that is
git remote add <short_name> <repository_url>
You can remove the remote using the keyword remove
git remote remove <short_name>
You can change the url of the existing remote repository using set-url command
git remote set-url <short_name> <repository_url>
You can also rename the short name using the command rename
git remote rename <short_name_old> <short_name_new>
You can check the list of remotes that you have already added using the command git remote -v
git remote add demo https://github.com/tyson332/DemoRepository.git git remote remove demo git remote -v
Note : When you clone a repository using an URL it automatically adds the remote for that url under the name of origin which is the default name provided by git.
Now lets push the files to the remote repository using the below command
git push -u <short_name> <branch_to_be_committed>
The -u attribute in the above command signifies that you need to save the configuration of committing files to repository of that branch always, so next time you need to push you can do just a git push and all the combination of repository url and branch is already maintained in the GIT configuration it automatically pushes it for you. You can also check this out in the local git configuration file (.git/config)
If you want more details about a remote you can run the command
git remote show <remote> <short_name>