Git Bash and GitHub Commands

Git Bash and GitHub Commands

References Link :

GIT CHEAT SHEET- github OFFICIAL

Hashnode - Git command - blogs

🅰️bbreviations used in Conventional Commits:

featA new feature
fixA bug fix
docsChanges in documentation
styleChanges that do not affect the meaning of the code
refactorCode changes that neither fix a bug nor add a feature
testAdding missing tests or correcting existing tests
choreOther changes that don't modify src or test files
perfA code change that improves performance
ciChanges to CI configuration files and scripts
buildChanges that affect the build system or dependencies
revertReverting a previous commit
mergeMerge branch or commit
configChanges to configuration files
depsDependency 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):

  1. Switch to the branch you want to delete:
git checkout branch_name
  1. Delete the branch locally:
git branch -d branch_name
  1. 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 -- .