Session 1.1: Git and GitHub
1. Install Git.
2. Create a GitHub account.
3. Create an empty repository on GitHub.
- After you log into your GitHub account, go to the "repositories" tab;
- Press the "New" button;
- Give a name to your repo, add a short description, leave it as a public repo, and add a README file. Then, press create.
4. Clone your newly created repository to your system
- Use GitBash, cmd, etc.
- Choose a directory that you want to clone the repository to.
- In Git Bash, you can use
git clone
followed by the repository address (URL), for example:
$ git clone http//github.com/~/WAD22.get
5. Change your current directory to the imported repository, for example:
$ cd WAD22
6. Check the status of your repository by using git status
.
$ git status
You should see the following message
On branch main Your branch is up to date with ‘origin/main’. nothing to commit, working tree clean
7. Within your working directory (project file), create an empty file and name it index.html. Check the status of your repository again. You should see the following message:
Untracked files: (use "git add <file>.. " to include in what will be committed) index.html nothing added to commit but untracked files present (use "git add" to track)
8. You can add the new files (currently in the Working directory) to the Staging area by using git add .
The "." will add all your new files in the Working directory to the Staging area.
$ git add .
Check the status of your repository again. You should see something like the following:
$ git status On branch main Your branch is up to date with 'origin/main'. Changes to be committed: (use "git restore –staged <file>…" to unstage) new file: index.html
9. You can commit these changes using git commit
, which will move the files/changes from the Staging area to the Local repo.
$ git commit –m "a text message to describe the commit".
–m "text": is a text message that is used to describe the commit.
10. Check the status of your repository again. You should see the following, which informs you that you can use git push
to publish your local commits.
$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) Nothing to commit, working tree clean
11. Push your local commits from the local repo to the remote repo using git push
, and you might be asked to authorize this activity by providing your credentials.
$ git push
11. The files/updates should have been pushed to the remote repo. Check your remote repo (GitHub) and you should see them.
12. Made some simple changes in your remote repo, i.e., change the readme. Then, update your local repo based on the remote one using git pull
.
$ git pull origin
13. Check your local repo and you should see the changes.
How can you add your team members to your repository?
- In GitHub, go to the repository where you want to add collaborators.
- Press on "setting".
- Within the "access" block, press on "Collaborators" (you might be asked about your credentials).
- Now, you can invite your group members by pressing the "add people" button.
- Your group members will receive emails inviting them to be collaborators, which they need to accept.