Using github for projects

This is a guide on git using bit and github for beginners that want to work collaboratively on a project with people. This works perfectly if your project doesn't have a git repository yet.

Setting up

We will mainly use the terminal for this. For linux people, just open a terminal for linux users and for window users open git-bash.

Next we have to go to the project directory, for this we will utilize ls, cd, and pwd. Type in pwd to see the directory we presently are in; ls to list the items in the current directory; and cd to got to a directory.

Once we reach the game directory, we're ready to start our own local git repository. This will let us have a versioning system in our computer.

git init
Git command to start a git repository

Linking to github

First start a new github repository. Adding the licenses, readme, and gitignore file are all optional but it shouldn't affect us that much. These will all be added to the github repository. and now we have two git repositories, one in our local machine and one remote in github.

To link our local repository to the remote one we use the git remote add command.

git remote add github https://github.com/<username>/<repo-name>.git
Linking remote repositories

Having linked them, we can now get changes from github and also upload our changes to github.

Using git

Github uses the name main for the default branch so let's use that locally too. To rename out current branch:

git branch -M main

Pulling changes from github

git pull github main

This command updates the local files to get the version from remotegithub and branch main.

The first time you run this you'll get the LICENSE, README.md and, .gitignore from github if you added them earlier. If you didn't, you can still add them later when you choose to.

Pushing changes to github

git push github main

This uploads our local commits to remote github.

The first time you run this you'll probably not see anything happen because we haven't made commits to add and track changes to our project files yet.'

Adding project files

git add <filename_1> <filename_2> ...

This tracks files that we want to add to the change that we want to make.

For our first time, we'd probably want to add all of our files first so something like

git add *

will probably work better for us as * matches all files

Commiting changes

git commit -m "commit message"

In git, changes we make are tracked only after we commit these changes.

More learning

Locally we can learn more about how to use a command by just appending -h to it

git branch -h
Example: for command help

But if you want more details you can also access the manuals:

git help
Accessing the manuals

Or if you just want to read a book