My list of useful git commands

As all those of us involved in the field of Computer Science know or should know, Git is by far the most widely used modern version control system in the world today. We utilized it in our everyday routine to keep track of our code changes and helps us…


This content originally appeared on DEV Community and was authored by Theodore Karropoulos

As all those of us involved in the field of Computer Science know or should know, Git is by far the most widely used modern version control system in the world today. We utilized it in our everyday routine to keep track of our code changes and helps us to work with other developers simultaneously and independently.

Although modern IDE and various tools provided by GitHub, Atlassian and other provide us an easy to use way to perform many git commands nothing compares to the power a terminal provides. Bellow you can find a list of my top git commands.

Rename latest's commit message

# This will pop up an editor window allowing us to pass the new commit message
git commit -amend 

# This will not pop up the editor
git commit -amend -m "Your new commit message"

Add file(s) into the latest commit. This requires that last change is not yet pushed into remote

# Add the file
git add the_file_you_want_to_add
# Amend without changing commit message
git commit --amend --no-edit

Reset to specific commit hash and discard any changes since that hash

git reset --hard <commit-hash>

Apply a commit from one branch to another

git cherry-pick <commit-hash>

Show commit logs and limit the output

git log -n <number>
# example git log -n 3
# or
git log -<number>
# example git log -3

If you are aware of any useful / useful git command and want to share it please do not hesitate to leave a comment!


This content originally appeared on DEV Community and was authored by Theodore Karropoulos


Print Share Comment Cite Upload Translate Updates
APA

Theodore Karropoulos | Sciencx (2021-12-13T20:47:27+00:00) My list of useful git commands. Retrieved from https://www.scien.cx/2021/12/13/my-list-of-useful-git-commands/

MLA
" » My list of useful git commands." Theodore Karropoulos | Sciencx - Monday December 13, 2021, https://www.scien.cx/2021/12/13/my-list-of-useful-git-commands/
HARVARD
Theodore Karropoulos | Sciencx Monday December 13, 2021 » My list of useful git commands., viewed ,<https://www.scien.cx/2021/12/13/my-list-of-useful-git-commands/>
VANCOUVER
Theodore Karropoulos | Sciencx - » My list of useful git commands. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/13/my-list-of-useful-git-commands/
CHICAGO
" » My list of useful git commands." Theodore Karropoulos | Sciencx - Accessed . https://www.scien.cx/2021/12/13/my-list-of-useful-git-commands/
IEEE
" » My list of useful git commands." Theodore Karropoulos | Sciencx [Online]. Available: https://www.scien.cx/2021/12/13/my-list-of-useful-git-commands/. [Accessed: ]
rf:citation
» My list of useful git commands | Theodore Karropoulos | Sciencx | https://www.scien.cx/2021/12/13/my-list-of-useful-git-commands/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.