Learning Objectives:
...
First step is to create a local copy of the repository. We'll do that by using the git clone command followed by the URL of the repo. GitHub conveniently lets us copy the URL from our repo from the interface so that we don't have to type it.
...
We got to remote repository set up on GitHub. So let's use it. We can send our changes to that remote repository by using the git push command which will gather all the snapshots we've taken and send them to the remote repository. Once again, we're asked for our password. After that, we see a bunch of messages from git related to the push.
...
Git already comes with a credential helper baked in. We just need to enable it. We do that by calling git config --global credential.helper cache
...
Now that we've enabled the credential helper, we'll need to enter our credentials once more. After that, they'll be cached for 15 minutes.
To check this, we can try another git command, git pull which is the command we use to retrieve new changes from the repository. We'll enter our credentials on the first call to the command and they'll be cached, so we won't need to enter them again.
...
Using a Remote Repository
What is a remote?
When we clone the newly created GitHub repository, we had our local Git Repo interact with a remote repository.
Remote repositories are a big part of the distributed nature of Git collaboration. It let lots of developers contribute to a project from their own workstations making changes to local copies of the project independently of one another.
When they need to share their changes, they can issue git commands to pull code from a remote repository or push code into one.
There are a bunch of ways to host remote repositories. There is many internet-based Git hosting providers like GitHub, BitBucket or GitLab which offer similar services.
We can also set up a Git server on our own network to host private repositories. A locally hosted Git server can run on almost any platform including Linux, mac OS, or Windows. This has benefits like increased privacy, control, and customization.
Using Git to manage a project helps us collaborate successfully.
Everyone will develop their piece of the project independently in their own local repositories maybe even using separate branches. Occasionally they'll push finished code into a central remote
...
repository where others can pull it and incorporate it into their new developments.
So how does this work?
Alongside the local development branches like master, Git keeps copies of the commits that have been submitted to the remote repository and separate branches.
If someone has updated a repository since the last time you synchronize your local copy, Git will tell you that it's time to do an update.
If you have your own local changes when you pull down the code from the remote repo, you might need to fix merge conflicts before you can push your own changes.
In this way Git let's multiple people work on the same project at the same time. When pulling new code it will merge the changes automatically if possible or will tell us to manually perform the integrating if there are conflicts.
So when working with remotes the workflow for making changes has some extra steps.
Will still modify stage and commit our local changes.
After committing, we'll fetch any new changes from the remote repo manually merge if necessary and only then will push our changes to the remote repo.
Git supports a variety of ways to connect to a remote repository. Some of the most common are using the HTTP, HTTPS and SSH protocols and their corresponding URLs.
HTTP is generally used to allow read only access to a repository. In other words, it lets people clone the contents of your repo without letting them push new contents to it.
Conversely HTTPS and SSH, both provide methods of authenticating users so you can control who gets permission to push.
The distributed nature of the work means that there are no limits to how many people can push code into a repository.
It's a good idea to control who can push codes to repos and to make sure you give access only to people you trust.
Web services like GitHub, offer a bunch of different mechanisms to control access to Repositories.
Some of these are available to the general public while others are only available to enterprise users.
Working with Remotes
Fetching New Changes
...