The model of work
The standard approach to work with a project is to have a local copy of the repository and commit your changes to this copy rather than to remote repo hosted on GitHub through the web interface. This local repository has the full version history of the project which can be useful when developing without an internet connection. After you've changed something in the local repo, you can push your changes to the remote repository to make them visible to other developers.
The picture below shows the model of how to work with GitHub.
This picture demonstrates two separated areas: GitHub and your computer.
First, consider the GitHub's area. There are two repositories:
- upstream is an original project's repo that you have forked
- origin is your fork (copy) on GitHub to which you have full access
To provide changes from your fork to the original project's repo, you need to make a pull request as we did before.
If you want to make small changes in your repo (fork), you may use GitHub's web interface. But this approach is not convenient when developing programs, because you often need to run and debug them locally. The standard way is to create a local clone of a remote repository and work with it locally, periodically pushing changes to the remote repo.
Installing Git
In order to continue this tutorial, you need to install Git locally, if you do not already have it. Just follow these instructions according to your operating system. If you do not like this manual, you may Google another one.
To check that Git was successfully installed, enter the command below in the terminal to display the version of your Git:
git version
git config --global user.name <YOUR_NAME>
git config --global user.email <EMAIL>
Cloning a repo
git clone https://github.com/hyperskill/intro-to-github.git
Modifying contents locally
git status
On branch master
Your branch is up-to-date with 'origin/master'.
git branch edit-readme
git checkout edit-readme
git status
On branch edit-readme
nothing to commit, working tree clean
The basic workflow goes something like this:
You modify files in your working copy.
You selectively stage changes you want to be part of your next commit.
You perform a commit that includes your changes.
modified: README.md
And then stage this changes using add:
git add README.md
git commit -m "Add information about local repository in readme file"
Pull & Push
git push --set-upstream origin edit-readme
git push
git pull