====== 'git' Commonly Used Commands ====== Please note the commands listed here may only work after an [[git_configuration#initial_configuration|initial configuration]] has been made. \\ ==== Display the Current Status of a Repo ==== 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 [['git' GUI Command Requirements|a GUI program]] that shows even more information: gitk --all \\ ==== Commiting Changes ==== \\ === Staging Changed Files === Once [[#Display the Current Status of a Repo|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 ~~codedoc: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 [[#Display the Current Status of a Repo|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 ~~codedoc:"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 //Fix**ed** a typo in several files//. For detailed conventions see: * **Commit Message Guidelines**\\ [[https://gist.github.com/robertpainsi/b632364184e70900af4ab688decf6f53]] \\ 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 [[#Committing Staged Files|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//