The Basics of Git

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 as described here.

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.

git config

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.

git status

Determine the status of your local git repository by executing the command git status. 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 lab01 directory. 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 status command 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.

git add

Add the ‘aboutme.txt’ file to your local repository 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 committed (it is staged to be committed).

git commit

The next step is to commit the file to your repository. Use the 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 editor 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.

git push

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.

Making changes

Open the ‘aboutme.txt’ file and add a 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 git commit. 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.

.gitignore

When creating completing your laboratory assignments you will be generating a lot of intermediate files that you do not want to include in your repository. These files include temporary files, bitstreams, and other files that are generated by the Vivado tools. It is helpful to let your git repository know that these files should be ignored. This can be done by creating a file named ‘.gitignore’ in the directories of your repository. This file should contain a list of files and directories that should be ignored by git. The following example shows a ‘.gitignore’ file that ignores all files within the proj_buttoncount directory. You will want to create a similar file in each of your lab directories to ignore the Vivado generated files.

./proj_buttoncount/*

Git Tutorials

There are a lot of good tutorials and demos on using Git. Some good ones are summarized below:


Last Modified: 2024-07-01 00:08:02 +0000