Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

GIT Bash Commands

Uploaded by

indgstreturns
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

GIT Bash Commands

Uploaded by

indgstreturns
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

GIT Bash commands

Cloning a Repository

To clone a repository from a remote server (like GitHub), use the git clone command
followed by the URL of the repository:

git clone <repository_url>

For example, to clone a repository named example-repo from GitHub:

git clone https://github.com/username/example-repo.git

Basic Git Commands After Cloning

Once you have cloned the repository, you can navigate into the repository's directory using cd
<repository_name> if you're not already there.

Checking Repository Status

To check the current status of your repository (e.g., modified files, untracked files), use:

git status

Adding Files to Staging Area

To stage files for the next commit (prepare files to be included in the next commit), use:

git add <file_name> # Stage a specific file


git add . # Stage all files in the current directory
git add -A # Stage all files in the entire repository

Committing Changes

To commit staged changes to the repository:

git commit -m "Commit message here"

Replace "Commit message here" with a brief, descriptive commit message summarizing
your changes.

Pushing Changes to Remote Repository

To push committed changes to the remote repository (typically where you cloned from):
git push

If it's your first push or if you are pushing to a new branch, you might need to set the upstream :

git push -u origin <branch_name>


Replace <branch_name> with the name of your branch, usually main or master for the
default branch.

Additional Git Commands


Pulling Changes: To fetch and merge changes from the remote repository into your current
branch:

git pull

● Creating a Branch: To create a new branch and switch to it:


git checkout -b <branch_name>
● Switching Branches: To switch between branches:

git checkout <branch_name>


● Viewing Commit History: To view a log of commits:

git log
● Undoing Changes: To discard changes in your working directory:
git checkout -- <file_name> # Discard changes in a specific file

git checkout . # Discard changes in all files

● This should give you a good starting point with Git Bash for typical repository
interactions. Adjust commands based on your specific repository workflow and needs.

Branching and Merging


List Branches: To list all branches in your repository:
git branch

● Delete Branch: To delete a branch (only if it's fully merged into another branch):
git branch -d <branch_name>
● Merge Branch: To merge another branch into your current branch:
git merge <branch_name>
● Working with Remote Repositories
Fetch: To fetch changes from the remote repository without merging:
git fetch

● Pull: To fetch and merge changes from the remote repository:


git pull
● Remote: To view remote repositories:
git remote -v # View remote URLs
● Undoing Changes
Reset: To reset the index and working directory to a specific state (use with caution):
git reset <commit_hash> # Reset to a specific commit

● Revert: To create a new commit that undoes changes made to a specific commit:
git revert <commit_hash>
● Inspecting Changes
Diff: To show changes between commits, commit and working tree, etc.:
git diff # Show changes between the index and working tree
git diff <commit> # Show changes between the index and specific
commit

● Tagging
Tag: To create, list, delete, or verify a tag object signed with GPG:
git tag # List tags
git tag <tagname> # Create a tag

● Configuration and Information


Config: To set or get configuration variables:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

● Help: To get help about Git commands:


git help <command> # Get help for a specific command

git --help # General Git help

These commands cover additional functionalities and scenarios you might encounter while
using Git. Depending on your specific workflow and needs, you may find yourself using these
commands frequently to manage and collaborate on your projects effectively.

You might also like