'git' Commonly Used Commands

Please note the commands listed here may only work after an initial configuration has been made.

Used to see if there are new files, uncommitted changes, or commits (changes) that have not yet been pushed to a remote repository.

git status

The command below starts a GUI program that shows even more information:

gitk –all

Staging Changed Files

Once the status has been checked, individual files can be committed, and changes that have been committed can be pushed to a remote repo, e.g. on GitLab or Github.

Often it is good practice to commit changes together that have been made for the same reason, e.g. to fix a particular problem. So selected files can first be added to a list (this is called staging), and once the list is complete, all files that have been staged can be committed in one step, with a single commit message indicating the reason for the changes.

Add a single changed file to the staging area:

git add my_file

Add all changed or new files in the current directory to the staging area:

git add *      # if command is run on Linux/Unix or 'git bash' on Windows
git add *.*    # if command is run on Windows 'cmd' window

Add all changed or new files in the current directory and all directories below to the staging area:

git add .

Add all updated files (changed files already managed by git) to the staging area:

git add .

If the status is displayed repeatedly, the staged files are shown separately from changed files that have not (yet) been staged.

Committing Staged Files

Once all files that are to be committed in one step have been staged, they can be committed in a single step.

The following command can be used to commit the changes with a short, single line commit message describing the reason for the changes in the staged files:

git commit -m "Fix a typo in several files"

With git it is good practice to write commit message in a way telling what happens if the commited changes are applied. In the example above, this means someone applies the patch/commit to Fix a typo in several files, so it does not read Fixed a typo in several files.

For detailed conventions see:

The command below does an interactive commit, where a text editor is opened to enter a short, single line as title, then a blank line, and additional lines for an more exhaustive explanation of the changes:

git commit

Pushing Commits to a Remote Repo

Once the changes have been committed to the local repo it is often useful to push them also to a remote repo, e.g. hosted on GitLab or Github.

The command

git push

is sufficient if only a single remote repo has been configured.

Martin Burnicki martin.burnicki@burnicki.net, last updated 2021-07-29

  • miscellaneous_tips/20_software_development/git_notes/git_commonly_used_commands.txt
  • Zuletzt geändert: 2021-07-29 17:52
  • von martin