Commands related to a remote repository:
git clone git@github.com:USER-NAME/REPOSITORY-NAME.git
git push or git push origin main (Both accomplish the same goal in this context)
Commands related to the workflow:
git add .
git commit -m "A message describing what you have done to make this snapshot different"
Commands related to checking status or log history
git status
git log
The basic Git syntax is program | action | destination.
For example,
git add . is read as git | add | ., where the period represents everything in the current directory;
git commit -m "message" is read as git | commit -m | "message"; and
git status is read as git | status | (no destination).
Delete commits:
git reset --hard HEAD~1 - delete last commit
You can also remove up to a specific commit using a commit’s hash, like so:
git reset --hard <hash>
To delete commits from remote, you will need to push your local changes to the remote using the git push command.
git push origin HEAD --force
Undo commit, but keep changes:
git reset --soft HEAD~1
gitk - display git in a desktop window
git config --global --list - list git repositories config(username, email)
git config --global user.name "<username>" - set global git username
git config --global user.email <email> - set global git email address
git commit -am "commit" - add files and commit at the same time
git add --patch - view file changes since the last commit
git log --oneline --graph - log commits one line
git restore --staged . - restore all staged files
git checkout <commit-hash> "filename" - request the contents of the file in the included commit
git checkout HEAD~1 - step back 1 commit
git checkout --. - reverse git add .
git checkout -b <new-branch> add and switch to a new branch
git checkout <branch-name> - move to another branch
git merge <branch-name> - merge another branch with the main branch
git rebase <branch-name> -> git add . -> git rebase --continue - merge another branch from master branch
git rm <filename> - delete file and add to stage
git checkout main - return to the last commit on the main branch
git checkout HEAD~1 -> git checkout -B main - merge the main branch into the current commit
git reflog -> git checkout <commit-hash> - display all previous logs and reset the desired commit
git mv <current-path/filename> <new-path/filename> - moving files in git and add to stage
git diff HEAD~1 HEAD - display the difference between current status and previous commit
git reset --soft HEAD~1 - delete last commit, keeping changes
git add *.<file-extension> - add all with this extension
git branch -D <branch-name> - delete branch
ssh keygen -t rsa -C "<email-address>" - generate public/private key
cat c/users/username/.ssh/id_rsa.pub - copy public key to github -> Your Profile=>Edit Profile=>SSH and GPG Keys
git rebase <new-branch>=>git commit -m "commit"=> git push -u <new-branch> - push a new branch to github and follow this branch from local git repo
git commit -m "<commit-message> Fixes#<issue-number>" - resolve an issue on github in master branch
coinvest
No comments yet