Skip to content

mrddter/git-cookbook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 

Repository files navigation

Git Commands

Align specific branch with main

git pull origin main

Reset all changes

git fetch origin
git reset --hard origin/main
git clean -fdx
git pull

Reset to specific commit

git reset --hard <commit>
git push -f

Reset last commit without change files (if no push is made)

git reset --soft HEAD~1

Reset last commit and reset all changes (be carefull)

git reset --hard HEAD~1

Delete local and remote branch

git branch -a
git branch -d <local-branch>
git push <remote> --delete <branch>

To force the local delete, use:

git branch -D <local-branch>

Cleanup all history commits

git checkout --orphan latest_branch
git add -A
git commit -am "clean up"
git branch -D main
git branch -m main
git push -f origin main

Chained all in one command:

git checkout --orphan latest_branch && git add -A && git commit -am "clean up" && git branch -D main && git branch -m main && git push -f origin main

Add new repo to existing folder

git init
git add .
git commit -m "first release"
git remote add origin git@github.com:mrddter/new_repository.git
git push -u origin main
(optional) git push -f origin main

Change remote url

git remote set-url origin git@github.com:mrddter/new_repository.git

Verify that the remote URL has changed:

git remote -v

Change git user

git config --list
git config user.email my@email.com
git config user.name "myname"

Change git user (globally)

git config --list
git config --global user.email my@email.com
git config --global user.name "myname"

Merge two branches

git checkout <to-branch>
git merge <from-branch>

About

A simple collection of Git commands

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published