Git - Command Reference
Common Commands
Task | Command |
---|---|
Add changes to staging | git add . |
Commit changes | git commit -m "Update" |
Pull code from a branch | git pull origin master |
Push code to a branch | git push origin master |
Branch Commands
Task | Command |
---|---|
List branches | git branch |
Create a new branch | git branch <new-branch-name> |
Switch to a branch | git checkout <branch-name> |
Delete a branch | git branch -d <branch-name> |
Merging Branches
Task | Command |
---|---|
Merge a branch into another branch | git merge <source-branch> |
Commit it | git commit -m "Merge feature-branch into main" |
Creating and Pushing a New Branch Based on Release
Task | Command |
---|---|
Fetch origin | git fetch origin |
Create new feature branch | git checkout -b new-feature-branch origin/release |
Push feature branch | git push origin new-feature-branch |
Creating and Pushing a Daily Branch Based on Release
Task | Command |
---|---|
Create and switch to daily branch | git checkout -b daily-<date>-gr origin/release |
Push daily branch | git push origin daily-<date>-gr |
Code Library
Task | Command |
---|---|
Delete a remote branch | git push origin --delete <branch-name> |
Submodule Commands
Task | Command |
---|---|
Initialize submodules | git submodule init |
Update submodules | git submodule update |
Revert a commit
git log
to check loggit reset --hard HEAD^
git push origin <branch> --force
example
git log
git reset --hard d37c4bb36ebbb03e0f3beccb72418e153bf7b367
git push origin feat-country-comparison-gr-2024-3-20 --force
Revert git merge
Task | Command |
---|---|
Abort a merge in progress | git merge --abort |
Replace git commit
Task | Command |
---|---|
Amend the last commit message | git commit --amend -m "new message" |
example
git commit --amend -m "feat(cards): implement auto debit limit feature"
Git move - move div/file to another div/file
Task | Command |
---|---|
Move/rename files or directories | git mv <source> <destination> |
Git extra - copy div/file
Task | Command |
---|---|
Install git-extras for additional commands | brew install git-extras |
Reference | https://formulae.brew.sh/formula/git-extras |