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.gitPushing 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 shortPulling Changes
The git pull command downloads changes that others have pushed and merges them into your local branch.
git pullAlways 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.gitThe Typical Daily Workflow
git pull— get the latest changes.- Edit your files.
git add .— stage your changes.git commit -m "..."— save a snapshot.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
*.logNever commit secrets such as passwords or API keys. Once pushed to GitHub they may remain in the history even after deletion.
Discussion
0No comments yet — be the first to leave one!