3. Working with Remote (push)
git push
This command Is most commonly used to publish and upload local changes to a remote central repository. If a local repo is connected to a remote repo, local chanages changes should be reflected on the remote repo by executing a git push
and one of it's sub-commands. Doing this allows one team member to share the modifications with other remote team members.
When working in a team environment it would be customary for one person to create the initial project structure, push this up to their remote repo, and all other team members would then clone that single repo down.
Before you begin, create a remote repo on bitbucket, github, gitlab, or a remote repo of your choice. Be sure that not to create a README file or any other content on the remote repo.
The remote should display a message like this
The important command here is the git remote add origin...
This connects your local repo to the remote repo.
Start with a fresh directory called remotes and initialise it as a git repo - git init
Use the git remote add origin
command from your remote repo to connect the local repo to the remote repo. Nothing will change on the remote repo until you perform a git push
.
Create the file six_honest_serving_men.txt and populate it with the following text
I keep six honest serving-men
(They taught me all I knew);
Their names are What and Why and When
And How and Where and Who.
I send them over land and sea,
I send them east and west;
But after they have worked for me,
I give them all a rest.
A poem by Rudyard Kipling
Stage and commit the changes.
Verify the branch you are working (it should be main) with the command git branch
Type the command
git push origin main
Visit your remote repo (you may need to refresh the page). The files on your local system should now be present on your remote repo.
Let’s make some changes and see how they affect the remote repo. Add the rest of the poem to the file.