Github is powerful of its collaboration tools that allows everyone to make contributions to any public repository (project). But how can we contribute (make changes) to a repository?
Before making any changes, we need to clone (download) the repository from remote to your local machine.
- Have access to the repository
If you have access to a repository, which means you can do a push, merge or other actions. You can just clone the repository to your local machine, make changes and push it to the remote repository.
- Have no access to the repository
Here's where fork come to place, if you have no access to a repository, you can only fork it to your own repository, clone it, make changes, and finally you make a merge your own repository (changes) into the original repository via pull request.
In our case, we grant all of you the write access to the CPS-Study-Club
if you're a member of us. So you can directly clone the repository and do the push and other actions.
- Copy the remote URL Make sure you're in the root directory of the repository to see the green code button.
- Place it to the terminal
# /usr/development/
# Clone the repository directly to under the directory terminal
git clone [email protected]:cpsumsu/CPS-Study-Club.git
# /usr/development/Study-Club/
# If you want to clone only the content of the repository without the root directory
git clone [email protected]:cpsumsu/CPS-Study-Club.git .
Simply means making changes on your local machine, then upload it to the remote repository. To do so, we need git to recognize the changes of the file.
Git will automatically detect any changes of all the files under the repository, but it won't save it without you explicitly tell git to store the changes. And it can show you where's changed.
git status
For example, when I create a new file, it shows the
untracked files:
and the name of the files.
Another case would be making changes to a existing file.
Here we add the changed file to the staging area (storing in somewhere and waiting for the next commit), commit is basically means saving the changes as a snapshot, where we can revert our codes to a specific version when we messed up something in the future.
- Add the changed files
# git add <filename>
git add naming-convention.md
It will show nothing if adding is successful.
- Commit the changes
git commit -m "add file - naming-convention"
It's important to attach the commit message with
-m
, so that the others understands what's your commit all about.
After finish the commit of the changes files, you're now able to push your changes to the remote repository!
# git push <remote-repository> <remote-branch>
git push origin main
origin would be
[email protected]:cpsumsu/CPS-Study-Club.git
and created by default when we clone the repository.