Commit code

git add .
git commit -m "feat: xxxxxx"

Undo the last commit (keep changes)

git reset --soft HEAD~1

This removes the last commit while keeping your working tree changes.

git reset parameters

--mixed
do not discard working tree changes, cancel the commit, and unstage changes (cancel the git add . operation). This is the default parameter.

--soft
do not discard working tree changes, cancel the commit, and keep changes staged.

--hard
discard working tree changes, cancel the commit, and unstage everything. After completing this operation, it is restored to the last commit state.

How to migrate a git repository to another remote location

Method 1

git remote set-url origin remote_git_address
git push

This method will only migrate the current branch to the new git.
In addition, this method could meet errors and fail, such as “error: source ref specification master does not match”.

Method 2 (better)

git push --mirror remote_git_address

This method only needs one command to finish this job. Note: --mirror pushes all refs and can overwrite the destination repo.

How to save username and password of git in Ubuntu

nano ~/.gitconfig

Edit the config file and set this config:

[credential]
    helper = store

Content licensed under CC BY-NC-SA 4.0.

Comments

⬆︎TOP