Set global user name and email:
git config --global user.name YourUserName
git config --global user.email YourEmail
git config --global user.name ashraf
git config --global user.email example@gmail.com
-
add remote url:
git remote add origin <remote-name>
-
change remote url:
git remote set-url origin <new-remote-name>
-
"refusing to merge unrelated histories"
git pull origin master --allow-unrelated-histories
-
delete a remote
git remote rm remote_name
# Example
# Current remotes
origin https://github.com/OWNER/REPO.git (fetch)
origin https://github.com/OWNER/REPO.git (push)
test_remote https://github.com/FORKER/REPO.git (fetch)
# Delete test_remote
git remote rm test_remote
-
create a branch :
git checkout -b <branchName>
-
show current branches :
git branch
-
move to another branch
git checkout <branchName>
-
pull update from branch
git pull origin <branchName>
-
push a branch into host
git push origin <branchName>
-
merge a branch
go to the branch where you want to merge then enter bellow command
git merge <branchName>
-
delete a branch(local)
git branch -d <branchName>
-
delete branch from remote
git push origin --delete <branch> # Git version 1.7.0 or newer
git push origin :<branch> # Git versions older than 1.7.0
-
Show log
git log
-
Show a commit
git show <commit_id>
-
Show a commit like log
git show <commit_id> --no-patch
-
Show only commit message log
git log --pretty=oneline --abbrev-commit
-
Fix the previous commit by removing it entirely
git reset --hard HEAD^
-
Delete last 2 commit from local reporsitory
git reset --hard HEAD^2
Here 2 is last two commit, if we want to delete last 3 commit then use 3