A way to improve the courses score by using git

4 minute read

Published:

In this article we will talk about using git to collaborate with other people and control the code version. And below is the basic git command which use most frequently for collaborate with you team member.

If you want more details or information about how to use git you can use the reference link or search online.

Preliminaries

In git the file have four status:

Untracked: This means the file is not tracked by the git

Unmodified: After each commit, the file will become unmodified.

Modified: This means this file have been modified after last commit.

Staged: After you modify a file you can add them to the stage area and later commit.

git file four status

figure1. Git file four status.

For Windows user:

You can navigate to the directory you want and right click, then choose the Git bash here to open the Git bash and type the following command.

For Windows 11 user, you need to click the “see more option” after right click, then you will see the “Git bash here”

For Linux user:

You can use Ctrl + Alt + T to open the Terminal and use cd to navigate to your directory

Or you can use file app to navigated to the directory and right click, choose “open in Terminal”, then type the following code.

1. Add file to stage area

  • Adds file changes to the staged area in preparation for a commit.

git add

you can use the command below (remember to replace the file_path to you real file path):

git add file_path

you can add multiple files at one time by use the space to separate them like below:

git add file_path1 file_path2

2. Commit the change

  • Commits the staged changes to the local repository with a descriptive message.

You can use the command below:

git commit -m "descriptive message"

3. git status

  • Displays the status of the working directory and staging area.

You can see that this command will show all the file status in the current repository.

And the first line will show the current branch you are in.

git status

You can use the command below:

git status

4. git pull

  • Fetches changes from a remote repository and integrates them into the local repository.

This command will update you local code to the newest version of the remote code.

git pull

You can use the command below:

git pull

5. git push

  • Pushes committed changes to a remote repository.

This command will push the last commit to the remote repository.

you can use the command below:

git push alias/branch_name

The alias here is mean the alias of you remote repository you set, most situation is origin.

The branch_name is the branch you want to push to remote repository.

6. git checkout

  • Switches to the specified branch.

You can use the command below (Remember to replace the branch_name to your real branch name):

git checkout branch_name

7. git log

  • Displays a log of commit history.

You can use this command to see the commit history and count the commit

You can use the command below:

git log

You can add tag “–oneline”, which will only show one line for one commit.

You can use the command below:

git log --oneline

Cheat sheet

Click below to see the Git cheat sheet

Git Cheat sheet

💥 Attention

Don’t directly make change in the main branch.

Don’t directly make change in the main branch.

Don’t directly make change in the main branch.

Usual Step

  • Before you start change to the code, do git pull to get the newest version of the code.
  • Check the branch you are in, if not in you own branch, change to you own branch. Don’t directly change the code in main branch.
  • Change the code.
  • After modify the code, add the file to stage by using git add.
  • Commit the change will a clear descriptive text.
  • Push you own branch to the remote repository.
  • Go to the GitHub to pull request to merge the code.

Reference

Pro Git

Missing semester