Skip to content

Latest commit

 

History

History
171 lines (132 loc) · 3.03 KB

File metadata and controls

171 lines (132 loc) · 3.03 KB

Git


[PINNED]

git commit -am "[0.1.1] "

git log --oneline

Initialize / Create a repo

git init
git add .
git commit -am "init"

git remote add origin <https://github.com/ThisoeCode/acme.git>

:: if LICENSE or README was added on GitHub repo creation
git pull origin main --allow-unrelated-histories

git push -u origin main

Use previous commit to create branch

git checkout -b new_branch_name commit_hash

Create an empty orphan branch

(Old way)

git checkout --orphan new_branch_name
git rm -rf .

(New way)

git switch --orphan <branchname>
git commit --allow-empty -m "Initial commit on orphan branch"
git push -u origin <branchname>

Merge from <branch-name> to "main" branch

git checkout main
git merge <branch-name>
git checkout app-router

Modify the comment message of last commit

git commit --amend -m "New message"

List all branch names / List all remote names

git branch -a
git remote

Delete branch

git branch -d <branch-name>
git push origin --delete <branch-name>

Find (and switch to) which branch a commit is on using its hash

git branch --contains <commit-hash>

Force push

git push --force origin <branch-name>

See status of all branches & Push all

git branch -vv
git status -sb
git push --all

Commit current status in a new branch temp and recover main branch

git checkout -b temp
git add .
git commit -m "Temporary commit before reverting errors"
git checkout main
git reset --hard HEAD
:: git push origin temp

Go back to previous commit

See a safer way

git reset <hash> --hard
git reset bc5ca7 --hard

Move file.txt from sub-branch to main branch (CAUTION: overwrite)

git checkout <branch-name> -- <file.txt>

After changing the repo name on GitHub, change local Git repo's remote URL

  1. check the current remote URL
git remote -v
  1. change URL
git remote set-url origin <https://github.com/ThisoeCode/NEW-REMOTE-URL.git>

Revert (as a new commit)

git log --oneline

git revert --no-commit a1b2c3d..HEAD
git commit -m ""

Unstage: Remove (untrack) staged file / dir

git rm --cached <file_name>
git rm -r --cached <folder_name>

GitHub

Multi-party work merge request acceptance via pull (from GitHub tips)

:: 1. Clone the repository or update your local repository with the latest changes.
git pull origin main
git pull
:: 2. Switch to the base branch of the pull request.
git checkout main
:: 3. Merge the head branch into the base branch.
git merge origin/<user>/<branch>
:: 4. Push the changes.
git push -u origin main
git push

Refer & auto-close an Issue

git commit -m "Fixed foo bar issue

Closes #1
"

Supported keywords include:
close closes closed fix fixes fixed resolve resolves resolved