https://github.com/faizulislamfair/git_commands
A repo for learning and recalling git commands!
https://github.com/faizulislamfair/git_commands
git
Last synced: 5 months ago
JSON representation
A repo for learning and recalling git commands!
- Host: GitHub
- URL: https://github.com/faizulislamfair/git_commands
- Owner: faizulislamfair
- Created: 2021-11-22T09:17:44.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-19T13:43:58.000Z (about 2 years ago)
- Last Synced: 2025-04-07T19:46:24.838Z (about 1 year ago)
- Topics: git
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Git Commands
## To setup username globally
### git config --global user.name "username"
## To setup email globally
### git config --global user.email "email"
## To change username globally
### git config --global user.name "username"
## To change email globally
### git config --global user.email "email"
## To check if the setup is complete
### git config --list
## To exit the list
### press 'q'(just q)
## To see the username
### git config user.name
## To see the email
### git config user.email
## To delete branch locally,
### git branch -D branch_name
## To delete branch remotely,
### git push origin --delete branch_name
## To download latest changes from a remote repository to local machine
### git fetch
## To integrate changes from one branch into another
### git checkout branch_to_merge_into
### git merge branch_to_merge_from
## To download latest changes from a remote repository to local machine and integrate into current branch (git fetch + git merge)
### git pull
## To remove a specific staged file (only added/staged, not committed) or unstage
### git rm --cached file_name(with extension)
or,
### git reset file_name(with extension)
## To remove all unstaged changes and move head to specific point
### git reset commit_id
## To remove all staged and unstaged changes and move head to specific point
### git reset --hard commit_id
## To remove all staged files (only added/staged, not committed) or unstage
### git reset HEAD
## To remove all staged changes (even from files) and staged files(only added/staged, not committed) or unstage
### git reset --hard HEAD
## To exit from git log press 'q' (just q)
## To view all commits with ids in a clean way
### git log --pretty=oneline
## To view all commits with ids in a clean way (shorter version)
### git log --oneline
## To display changes between a specific commit and current head
### git diff commit_id
## To abort merge after getting conflict message
### git merge --abort
## To not lose changes by not committing yet and moving to another branch to work on something
### git stash
or,
### git stash -u
and then to apply changes after coming back later
### git stash apply index_number(0)
## To save stash with a custom message
### git stash push -m "message_name"
## To change name of most recent commit that hasn't been pushed to remote repo yet
### git commit --amend -m "new commit message"
## To change name of most recent commit that has been pushed to remote repo
### git commit --amend -m "new commit message"
### Plus
### git push --force
## To forcefully revert back to the state of the latest commit, discarding any local changes and disregarding any conflicts or warnings
### git checkout HEAD~ --force
## To move HEAD to a particular commit, push to repo and pull to master branch
### git checkout commit_id
### git add .
### git commit -m "commit message"
### git push origin HEAD:master --force
### Plus
### git checkout master
### git pull
## To bring in changes from a specific commit
## To bring in changes from one commit and commit directly in my branch
### git cherry-pick commit_id
or,
## To bring in changes from more than one commit and commit directly in my branch
### git cherry-pick commit_id_one commit_id_two
## To bring in changes from one commit and without committing directly in my branch
### git cherry-pick commit_id -n
then commit,
### git commit -m "commit_name"
## To undo changes introduced in a previous commit and commit
### git revert commit_id
### Plus
### :q (to exit)
## To replay all commits on our current branch on top of specified branch
### git rebase branch_name
## To edit commit history before rebasing
### git rebase -i branch_name