Skip to content

Latest commit

 

History

History
77 lines (60 loc) · 3.92 KB

how-to-use-git-en.md

File metadata and controls

77 lines (60 loc) · 3.92 KB

How to use Github

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?

How to Contribute?

Before making any changes, we need to clone (download) the repository from remote to your local machine.

  1. 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.

  1. 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.

Clone the repository

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.

  1. Copy the remote URL Make sure you're in the root directory of the repository to see the green code button.

Screenshot 2022-07-31 at 10 10 58 PM clone on terminal

  1. 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 .

Make Contribution

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.

How git recognize our changes?

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.

Show what's changed

git status

For example, when I create a new file, it shows the untracked files: and the name of the files.

git status

Another case would be making changes to a existing file.

Screenshot 2022-07-31 at 10 26 36 PM

Save the changes

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.

  1. Add the changed files
# git add <filename>
git add naming-convention.md

It will show nothing if adding is successful.

  1. 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.

commit and commit message

Ready to push

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.