Common Git Commands

Projects often use Git to manage files and code, and there are many Git management tools available. This article aims to provide beginners with some simple tutorials to help them quickly become familiar with Git usage methods.

Introduction to Git

To understand Git, you first need to understand the following scenarios:

  1. Workspace: The current working area, where modifications start.
  2. Staging: After modifications, changes are added to the staging area, preparing them for commit.
  3. Local Repository: The local code repository, where changes are stored and only affect your local code. This is one of the differences from SVN; after an SVN commit, changes are directly submitted to the remote server, whereas after a Git commit, changes are only stored in the local repository.
  4. Remote Repository: The remote code repository, where you synchronize your local repository to share your work with other developers.

As shown in the diagram above, commands are used to interact between different scenarios. For example, git add submits files to the staging area, then git commit moves files from the staging area to the local repository, and git push sends them to the remote repository. The interactions described so far occur within a single branch, but Git also offers more powerful features, such as creating different branches that can be split and merged as needed.

Common Git Operations

Operations in Git Bash

  • Open the project folder in your workspace, right-click, and select “Git Bash Here” to open the command input window.
image-20230227110553706
  • Commit files to the remote repository
image-20230227113823716
# Commit to local branch
git commit -m 'First commit'
# Check commit status
git status
# Push to remote branch
git push origin master
  • Modify the remote repository URL
image-20230227111620966
Administrator@PC-20220428VDVU MINGW64 /d/workspace/base (master)
$ git remote -v
origin  git@git.xxx.com:xxx/xx-base.git (fetch)
origin  git@git.xxx.com:xxx/xx-base.git (push)

Administrator@PC-20220428VDVU MINGW64 /d/workspace/base (master)
$ git remote set-url origin git.xxx2.com:xxx2/xx2-base.git

Administrator@PC-20220428VDVU MINGW64 /d/workspace/base (master)
$ git remote -v
origin  git.xxx2.com:xxx2/xx2-base.git (fetch)
origin  git.xxx2.com:xxx2/xx2-base.git (push)

Operations in TortoiseGit

  • Open the project folder in your workspace, right-click, and select “TortoiseGit” to open the TortoiseGit submenu.
image-20230227114139103
  • Commit files to the remote repository
image-20230227114644534
image-20230227114800828
  • Modify the remote repository URL
image-20230227121337431

Operations in IDEA

  • Commit code to the remote repository

Click VCS—Git—Commit File to open the dialog box

image-20230227122934822

Click VCS—Git—Push to open the dialog box

  • Modify the remote repository URL

Click VCS—Git—Remotes to open the dialog box, select the repository URL, and click Edit

By Tim

2 thoughts on “Common Git Commands”
  1. Полезный, вкусный и легкий салат, приготовление которого занимает считанные минуты. Сочные овощи способствуют тому, что семена чиа быстро набухают, поэтому долго ждать не придется. Просто подготовьте ингредиенты, смешайте и приступайте к трапезе

    Blog

  2. Можно сколько угодно рассуждать о том, что смузи – это всего лишь хайповый тренд. Но кроме того это еще и очень удобный и полезный перекус на скорую руку. И лично я уже не готова от них отказаться. Делюсь любимым рецептом тыквенного смузи

    Сайт

Leave a Reply

Your email address will not be published. Required fields are marked *