Lesson 4 of 5

Working with GitHub Remotes

Putting Your Project Online

GitHub hosts your Git repository on the internet. This gives you a backup, lets you work from any computer, and makes collaboration possible.

Remotes

A remote is a version of your repository stored somewhere else. The main remote is conventionally named origin.

Connecting a Local Repo to GitHub

After creating an empty repository on GitHub, link your local project to it.

git remote add origin https://github.com/yourname/project.git

Pushing Changes

The git push command uploads your local commits to the remote. The first push uses the -u option to remember the connection.

git push -u origin main   # first push, sets the upstream
git push                  # later pushes can be this short

Pulling Changes

The git pull command downloads changes that others have pushed and merges them into your local branch.

git pull

Always pull before you start working so you build on the latest version of the project.

Cloning an Existing Repository

To get a copy of a project that already exists on GitHub, use git clone. This downloads the whole project and its complete history.

git clone https://github.com/dccps/website.git

The Typical Daily Workflow

  1. git pull — get the latest changes.
  2. Edit your files.
  3. git add . — stage your changes.
  4. git commit -m "..." — save a snapshot.
  5. git push — share it with the team.

The .gitignore File

Some files should never be tracked, such as passwords or temporary build files. List their names or patterns in a file called .gitignore and Git will ignore them.

node_modules/
.env
*.log
Never commit secrets such as passwords or API keys. Once pushed to GitHub they may remain in the history even after deletion.
Next
How did you find this lesson?

Discussion

0
To join the discussion, comment and react, log in or create an account.

No comments yet — be the first to leave one!