1.9 KiB
1.9 KiB
Git Cheatsheet
1. Remote Repository Commands
- Clone a repository:
git clone git@github.com:USER-NAME/REPOSITORY-NAME.git - Push changes to a specific remote branch:
git push origin BRANCH-NAME - Pull changes from a specific remote branch:
git pull origin BRANCH-NAME
2. Workflow Commands
-
Add all changes to the staging area:
git add . -
Commit changes with a message:
git commit -m "Your descriptive commit message"
3. Checking Status & Log History
-
Check the current state and changes:
git status -
View the commit history:
git log
4. Branching
-
Create and switch to a new branch:
git checkout -b BRANCH_NAME -
Switch to an existing branch:
git checkout BRANCH_NAME -
List all branches:
git branch -
Delete a branch:
git branch -d BRANCH_NAME
5. Additional Commands
-
Show changes between the working directory and index:
git diff -
Revert changes from a specified commit:
git revert COMMIT -
Reset the current branch head to a specified commit:
git reset COMMIT -
Temporarily save changes:
git stash
6. Tips & Best Practices
- Use branches for development.
- Commit regularly with descriptive messages.
- Use pull requests to merge changes.
- Resolve conflicts promptly.
7. Basic Git Syntax (Simplified Model)
The basic Git syntax is program | action | destination.
For example:
git add .is read asgit | add | ., where the period represents everything in the current directory.git commit -m "message"is read asgit | commit -m | "message".git statusis read asgit | status | (no destination).git push origin mainis read asgit | push | origin main.