Important Git commands for daily use

Last updated on February 28th, 2023 at 10:38 am.

Git commands for daily use `

Git commands for daily use , Here are some git commands you may encounter in your daily usage.

Here is the GitHub repo with more Linux commands.

git init: For initializing new repository in the current folder.

git init

git clone : Clone an existing repo from Github or any other remote repository.

git clone https://github.com/rwahowa/Linux-commands.git


git add : For adding files to the staging area for commit to remote repository.

git add filename  # add a specific file

git add .   # Add the contents in the current directory


git commit : Commits the change with a commit mesage.

git commit -m "Commit message"

git push : Push to the remote repository.

#Add -u so that next time you can just do: git push

git push -u origin main

git pull : Pull changes from a remote repository and merge them to the local repo.

git pull origin main


git status : Find out the status of the repository: which files have been edited, added, or deleted.

git status


git branch : Shows the current branch and lists any other branches in the repository.

git branch


git checkout : Switch to a different branch.

git checkout branchname


git merge : Merge the changes from one branch into another.

git merge branchname


git log : View the commit history chronologically from newest to oldest.

git log

git revert : Revert a commit by creating a new commit that will undo the changes made by the former commit.

git revert HEAD~1
git revert commitID  # get id from git log

git cherry-pick : Apply the changes introduced by some existing commits. Apply changes made by a specific commit to the current branch.

git cherry-pick efghijk

git diff : Show the differences between the present working directory and the most recent commit.

git diff

Related : Set up SSH Authentication using Git Bash – Login for Linux Server.

git reset : Unstage changes from the repo staging area, or undoes a commit. Reset current HEAD to the specified state.

git reset app.py # unstage changes of this file
git reset HEAD~1 # undo the most recent git commit

git stash : Temporarily save changes to the current directory, giving you time to switch to a different branch without committing the changes. saves your local modifications away and reverts the working directory to match the HEAD commit.

git stash save "Work in progress" # stash changes
git stash list  # list saved stashes
git stash apply  # apply the most recent stash

git fetch : Get changes from a remote repository, but does not automatically merge them into the local repository.

git fetch origin

git merge –no-ff : Merge changes from one branch into another, creating a new commit even if the changes can be fast-forwarded.

git merge --no-ff branchname

git remote : Show the repositories that the local repo is connected to.

git remote
git remote -v # Show more info like the remote link

git branch -d : Delete a local branch.

git branch -d branchname

git tag : Create tags, which are used to mark specific points in the commit history.

git tag v1.0 # create a tag
git tag # list all tags

Comment Here

Join this free course:

How to host multiple WordPress
websites on a VPS

Close me!