This brief tutorial will help you learn the basics of adding, committing, and pushing files to your class GitHub repository. This tutorial assumes you have successfully created your class repo and imported the student starter code.
Begin this tutorial by changing into the ‘lab01’ directory of your class repository. This tutorial assumes that you are running all commands in this directory.
Begin by executing the command:
git config --list.
This command will display the current git settings.
Briefly review these settings and make sure your username and email are properly set.
Determine the status of your local git repository by executing the command
This command indicates if you have any differences in your local directory against your local repository.
$ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean
Since you haven’t made any changes, your directory and local repository match.
Create a new text file named ‘aboutme.txt’ in the
Include the following in this file:
- Where you are from
- List one or two hobbies you enjoy
- Your plans for this weekend
After creating this file, run the
git statuscommand again:
$git status On branch main Your branch is up to date with 'origin/main'. Untracked files: (use "git add <file>..." to include in what will be committed) aboutme.txt nothing added to commit but untracked files present (use "git add" to track)
The command highlights the ‘aboutme.txt’ file that is untracked in your repository.
Add the ‘aboutme.txt’ file to your local repoistory by using the command
git add aboutme.txt.
This adds the file to your repository.
Check the status of your repository after adding this file.
$git status On branch main Your branch is up to date with 'origin/main'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: aboutme.txt
This message indicates that the ‘aboutme.txt’ file is new but not yet commited (it is staged to be committed).
The next step is to commit the file to your repository.
git commit command to commit this file into your local repository.
Note that the ‘-m’ flag is used to provide a message with the commit.
If you do not include this flag, a text exitor will open up and force you to add a message with this commit.
$git commit -m "Adding new file" [main 0fd3866] Adding new file 1 file changed, 3 insertions(+) create mode 100644 lab01/aboutme.txt
Check the status of your repository:
$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
This message indicates that your current local branch is ahead of the remote repository by one commit.
Use the ‘git push’ command to ‘push’ this commit in your local repository to your remote repository.
$ git push Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 8 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 410 bytes | 410.00 KiB/s, done. Total 4 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), completed with 1 local object. To github.com:byu-ecen323-classroom/323-labs-wirthlin.git 34808ab..0fd3866 main -> main
Review the status of your local repository after performing this push.
Open the ‘aboutme.txt’ file and add line that specifies your favorite type of food. After changing the file, determine the status of the repository.
$ git status On branch main Your branch is up to date with 'origin/main'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: aboutme.txt no changes added to commit (use "git add" and/or "git commit -a")
Git informs you that the ‘aboutme.txt’ file has changed and does not match the local repository.
You can add the changed file to the repository by (1) adding the file with
git add and (2) performing a commit with
Update your repository by committing your modified file and pushing it to your remote repository.
This ‘aboutme.txt’ file will be a required part of your lab submission.
There are a lot of good tutorials and demos on using Git. Some good ones are summarized below: