Last active
December 2, 2023 09:33
-
-
Save abbas-v1/bfc9dcc7ab352b496cd2a4816b501811 to your computer and use it in GitHub Desktop.
Common GIT commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clone a remote repository on your local machine | |
``` | |
git clone <repository_url> | |
``` | |
List all local branches | |
``` | |
git branch | |
``` | |
List all local and remote branches | |
``` | |
git branch -a | |
``` | |
List all tags | |
``` | |
git tag -l | |
``` | |
Checkout a specific branch, tag, revision, file or a directory | |
``` | |
git checkout <branch_name> | |
git checkout tags/<tag_name> | |
git checkout <revision_sha> | |
git checkout origin/master -- <filename> | |
git checkout origin/master -- </directory/path/> | |
``` | |
Stashing changes | |
``` | |
git stash list | |
git stash | |
git stash pop | |
git stash drop | |
``` | |
Ignore changes in a file that is currently being tracked | |
``` | |
git update-index --assume-unchanged <file_name> | |
``` | |
Start tracking changes in a file that has been previously ignored | |
``` | |
git update-index --no-assume-unchanged <filen_name> | |
``` | |
Revert changes made in a previous commit | |
``` | |
git revert <revision_sha> | |
``` | |
Show change history of a file | |
``` | |
gitk <file_path> | |
``` | |
Resolve merge conflicts | |
``` | |
git mergetool | |
``` | |
If already in conflict state, and want to accept all of theirs | |
``` | |
git checkout --theirs . | |
git add . | |
``` | |
If already in conflict state, and want to accept all of ours | |
``` | |
git checkout --ours . | |
git add . | |
``` | |
Undo the act of committing, leaving everything else intact | |
``` | |
git reset --soft HEAD^ | |
``` | |
Undo the act of committing and everything you'd staged, but leave the work tree (your files intact) | |
``` | |
git reset HEAD^ | |
``` | |
Completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit | |
``` | |
git reset --hard HEAD^ | |
``` | |
Reset local branch to previous commit | |
``` | |
git reset --hard e3f1e37 | |
``` | |
Hard reset remote branch to previous commit | |
``` | |
git reset --hard e3f1e37 | |
git push --force origin develop | |
``` | |
Hard reset to clean untracked files and directories | |
``` | |
git clean -f -d | |
``` | |
Files changed in this branch | |
``` | |
git diff master.. --name-only | |
``` | |
Cherry-pick commits from one branch into another | |
``` | |
for commit in $(git log --reverse --pretty=%H --since="2021-05-27T17:19:00" --until="2021-05-30T12:03:00" --all); | |
do | |
git cherry-pick $commit | |
done | |
``` | |
Get changes from GitHub template | |
On the other repositories you have to add this template repository as a remote. | |
git remote add template https://github.com/bit-oasis/template-service.git | |
Then run git fetch to update the changes | |
git fetch --all | |
Then is possible to merge another branch from the new remote to your current one. | |
git merge template/main --allow-unrelated-histories | |
Rebase your branch to master branch | |
git rebase master | |
git push --force origin your_branch_name | |
If you have a branch A from master and then another branch B from A and want to connect B to master | |
git checkout B | |
git rebase A --onto master | |
git push --force origin B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
get changes from template