Version Control
Git: Getting started
Git: Getting started
  • Introduction
    • What is version control
      • Distributed VCS
      • Summary
    • What is Git?
      • A Short History of Git
      • Under the hood
      • The Three States
    • What is GitHub?
  • Setting up Git
    • Installation
    • First time setup
    • Creating a repo
  • Basic operations
    • Recording Changes
      • Add another file
      • Modify-stage-commit
      • Modify-direct commit
      • View log
    • Undo changes
      • Restore (modified)
      • Restore (staged)
      • Amend (rare)
    • Clone repos
  • Remote Repos
    • Configure remote
    • Push to remote
      • Push branches
  • Reference
    • My Git Tutorials
    • Git Official
    • Others
Powered by GitBook
On this page
  • Configure remote repository
  • Showing Your Remotes
  • Create a repository on GitHub
  • Push to GitHub repo
  • Add reference to our repository
  • Push to GitHub
  • Verify the GitHub Push
  1. Remote Repos

Configure remote

PreviousClone reposNextPush to remote

Last updated 2 years ago

Configure remote repository

To be able to collaborate on any Git project, you need to know how to manage your remote repositories. Remote repositories are versions of your project that are hosted on the Internet or network somewhere. Collaborating with others involves managing these remote repositories and pushing and pulling data to and from them when you need to share work.

The word “remote” does not necessarily imply that the repository is somewhere else on the network or Internet, only that it is elsewhere!

Showing Your Remotes

To see which remote servers you have configured, you can run the git remote command. It lists the shortnames of each remote handle you’ve specified. If you’ve cloned your repository, you should at least see origin — that is the default name Git gives to the server you cloned from:

git remote

Note: If you do not get any output, it means no remote servers are configured!

You can also specify -v, which shows you the URLs that Git has stored for the shortname to be used when reading and writing to that remote, v stands for verbose:

git remote -v

Create a repository on GitHub

You do not have an account, create a GitHub account and then from the homepage, create a New repository as highlighted in the below steps:

Push to GitHub repo

Using the commands which git is already showing, let us add and push our existing repository on to GitHub help with the below commands:

Add reference to our repository

git remote add origin https://github.com/ravirammysore/MyFirstRepo.git

Push to GitHub

The -u switch makes the remote GitHub repo the default for your existing project ('U' stands for upstream)

git push -u origin master

From next time we can simply specify push without specifying origin or master!

Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 8 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (12/12), 1024 bytes | 1024.00 KiB/s, done.
Total 12 (delta 0), reused 0 (delta 0)

To https://github.com/ravirammysore/MyFirstRepo.git
 * [new branch]      master -> master
 
Branch 'master' set up to track remote branch 'master' from 'origin'.
git status

On branch master

Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

We can also add the -f option in the above command to force the push. Sometimes our push operation may be rejected since there may be extra files present in GitHub (like readme.md file) which is not present in our local repository:

git push -u -f origin master

Verify the GitHub Push

To verify that the existing project was pushed to GitHub successfully, log into the GitHub website and browse the repository. All of the files from your existing project should be visible on GitHub’s.

So, refresh the browser and you should see the following: