Skip to content

Instantly share code, notes, and snippets.

@sayedulsayem
Last active July 31, 2023 11:22
Show Gist options
  • Save sayedulsayem/8ca1bd3a304f1425149012854ba45ea8 to your computer and use it in GitHub Desktop.
Save sayedulsayem/8ca1bd3a304f1425149012854ba45ea8 to your computer and use it in GitHub Desktop.
Useful git command
Show git log
git log
Add and commit at a time
git commit -am "Commit Name"
Add existing directory to an origin
git remote add origin http//........
list all remote branches
git branch -a
list all local branches
git branch -l
git branch
Creates a new branch.
git branch branch-name
Delete branch
git branch -d branch-name
Delete remote branch
git push origin --delete branch-name
Creates a new branch and also switches to it.
git checkout -b [branch name]
This command shows the differences between the two commit.
git diff one-commit-ID two-commit-ID
This command deletes the file from your working directory and stages the deletion.
git rm [file]
This command delete all data which is not commited
git checkout -f
Delete the last commit
git reset --hard HEAD~1
Delete specific commit
git reset --hard <sha1-commit-id>
if you want to change remote URL
git remote set-url origin git@hostname:USERNAME/REPOSITORY.git
Create git tag
git tag <tag_name>
Create git tag with message
git tag -a <tag_name> -m "message"
To see local git tag list
git tag
To see local git tag list with message
git tag -n
Switch to git tag
git tag <tag_name>
Push created git tags
git push --tags
Create git tag for commit
git tag <tag_name> <commit_sha>
Create Tag For Last Commit
git tag <tag_name> HEAD

(for the last commit)

git tag <tag_name> HEAD~1 

(for the commit before HEAD)

In order to checkout a Git tag
git checkout tags/<tag_name> -b <branch_name>
To fetch tags from your remote repository
git fetch --all --tags
To update local repository by fetching the remote tags available.
git fetch --tags
Delete a local Git tag
git tag -d <tag_name>
Delete a remote Git tag
git push --delete origin tagname
Merge steps
git push origin source-code
git checkout dev
git pull origin dev
git merge source-code

fixing merge conflict

git commit -am "something"
git push origin dev
Git staging
git stash

(Remonve all un-commit data)

git stash pop

(Get Stash data)

git stash clear

(Remonve all Stash data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment