Table of contents
References Link :
GIT CHEAT SHEET- github OFFICIAL
Hashnode - Git command - blogs
🅰️bbreviations used in Conventional Commits:
feat | A new feature |
fix | A bug fix |
docs | Changes in documentation |
style | Changes that do not affect the meaning of the code |
refactor | Code changes that neither fix a bug nor add a feature |
test | Adding missing tests or correcting existing tests |
chore | Other changes that don't modify src or test files |
perf | A code change that improves performance |
ci | Changes to CI configuration files and scripts |
build | Changes that affect the build system or dependencies |
revert | Reverting a previous commit |
merge | Merge branch or commit |
config | Changes to configuration files |
deps | Dependency updates or changes |
Configuring Git
# Set your username:
git config --global user.name "FIRST_NAME LAST_NAME"
# Set your email address:
git config --global user.email "MY_NAME@example.com"
git config --list
clear
Clone & Status
git clone https://github.com/Z-Other-Languages/git-command.git
cd myRepoFoldName
// The ls command stands for "list." It is used to list the contents of a directory
ls
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 25-02-2024 04:53 PM 51 README.md
Git Workflow:
Modify/New File -> Stage -> Commit
- Modified/NewFile -> add(staged) -> commit(unchanged/unmodified)
Git File Statuses Explanation
untracked - new files that git doesn't yet track
modified - changed
staged - file is ready to be committed
unmodified - unchanged
git status
add & commit
# Stage the changes made to index.html
git add index.html
# Stage the changes made to readme.md
git add readme.md
# Alternatively, stage all changes in the current directory and its subdirectories
git add .
# Commit the staged changes with a descriptive message
git commit -m "my message"
push
# Push the changes from the local 'main' branch to the remote repository named 'origin'
git push origin main
# To set up tracking for the main branch on the remote repository named 'origin',
# you can use the '-u' or '--set-upstream' flag with the first push
git push -u origin main
# After setting up tracking, for subsequent pushes, you can simply use:
git push
2. Local System Folder -> Git Hub
- Create a project in your PC folder and then upload it to the GitHub repository.
Branch Commands
Delete a branch :
To delete a branch in a GitHub repository using the command-line interface (CLI):
- Switch to the branch you want to delete:
git checkout branch_name
- Delete the branch locally:
git branch -d branch_name
- Push the deletion to GitHub:
git push origin --delete branch_name
Replace branch_name
with the name of the branch you want to delete.
After executing these commands, the specified branch will be deleted both locally and on GitHub. Ensure you have the necessary permissions to delete branches on the GitHub repository.
Merging Code
pull
Remote repo -> Local Repo
merge conflicts
Undo Changes
🗑️Discard Changes in a Repository
# Discard changes made to a specific file and revert it to the state it was in at the last commit.
git checkout -- <file>
# Discard changes made to all files in the current directory and its subdirectories,
# reverting them to the state they were in at the last commit.
git checkout -- .