KEMBAR78
Github | PDF | Utility Software | System Software
0% found this document useful (0 votes)
20 views3 pages

Github

The document provides a comprehensive overview of essential Git commands and concepts, including cloning repositories, staging changes, committing, branching, and merging. It also outlines the steps to push commits to GitHub, emphasizing the importance of proper configuration and the use of a .gitignore file. Key commands such as git add, git commit, git merge, and git checkout are explained with examples to facilitate understanding of Git's version control functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Github

The document provides a comprehensive overview of essential Git commands and concepts, including cloning repositories, staging changes, committing, branching, and merging. It also outlines the steps to push commits to GitHub, emphasizing the importance of proper configuration and the use of a .gitignore file. Key commands such as git add, git commit, git merge, and git checkout are explained with examples to facilitate understanding of Git's version control functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Git clone :– git clone <old_repo_link> <new_repo_name>

Lifecycle –
Repository – Committed changes
Working dir – temporary changes
Staging index – about to committ

1. git add:

 This command is used to add changes in your working directory to the staging area (index).
 Example: git add <file_name> or git add . (adds all changes).
 This stages the changes, preparing them for a commit.

2. git commit:

 This command commits the staged changes to your local repository.


 Example: git commit -m "Your commit message".
 It creates a snapshot of the changes and adds a message to describe what has been changed.

3. git show:

 This command shows information about a specific commit, object, or reference.


 Example: git show <commit_hash> will display details of a commit.
 It can be used to view the changes in a commit or the status of an object.

4. git diff:

 This command shows the differences between files or commits.


 Example: git diff will show the changes between the working directory and the staging area.
 Example: git diff <commit_hash1> <commit_hash2> will show the difference between two commits.

5. git restore:
 This command is used to restore files in your working directory or staging area.
 Example: git restore <file_name> will revert changes in a file back to the last committed state.
 It can also be used to restore files from a specific commit.

Using git add . is not always recommended because it stages all changes in the working directory,
including unintended files (e.g., debug files, build artifacts). This can lead to accidentally committing
unwanted changes. It's better to stage specific files using git add <file_name> to ensure only intended
changes are committed.

6. HEAD:

 In Git, HEAD refers to the current commit your working directory is based on. It points to the latest commit
in the current branch. When you checkout a branch, HEAD is updated to point to that branch's latest commit.
 Example: git checkout <branch_name> moves HEAD to the latest commit of the specified branch.
7. .gitignore file:

 A .gitignore file specifies which files and directories Git should ignore in version control. It’s typically used
to exclude files like build artifacts, temporary files, or sensitive data that you don’t want to commit to the
repository.

Branching
Branching in Git allows you to create separate lines of development within a project. It enables you to work on
different features or fixes independently without affecting the main codebase. Here's the concept explained
simply:

1. Main Branch :- The default branch (usually main or master) contains the stable version of the project.
2. Creating a Branch :- You create a branch to work on a specific feature or fix, leaving the main branch
unchanged.
o Example: git branch <branch_name> creates a new branch.
3. Switching Between Branches :- You can switch between branches using git checkout <branch_name>. This
changes the code in your working directory to match the branch you’re on.
4. Merging Branches :- Once your feature is complete, you merge the branch back into the main branch using git
merge <branch_name>. This integrates your changes.
5. Benefits :- Branching helps to work on multiple features concurrently without interfering with each other,
maintaining the stability of the main codebase.

8. Tag:

 A tag is a reference to a specific point in Git history, often used to mark release points (e.g., v1.0).

git tag -a <tagname> <commit_id> -m "<message>"

 Tags are typically used for marking versions or important milestones in a project.

9. Branch:

 A branch in Git is a pointer to a specific commit, allowing you to work on separate features or tasks without
affecting the main codebase.
 Example: git branch <branch_name> creates a new branch.
 Branches help with parallel development, keeping different features isolated.

10. Stash:

 git stash temporarily saves changes in your working directory that are not ready to be committed. This allows
you to switch branches or work on something else without losing your changes.
 Example: git stash saves your changes, and git stash pop restores them later.

11. Checkout:

 git checkout is used to switch between branches or restore files from a specific commit.
 Example: git checkout <branch_name> switches to the specified branch.
 It can also be used to discard changes in a file: git checkout -- <file_name>.
12. Merge:

 git merge is used to combine changes from one branch into another. It integrates the changes from a specified
branch into the current branch.
 Example: git merge <branch_name> merges the specified branch into the current branch.
 Merging helps combine work done in parallel, but may require resolving conflicts if changes overlap.

Steps to Push a Commit to GitHub:


The steps you provided are close, but there's a slight mistake in your email configuration. The command
should be git config --global user.email instead of git config --global user.mail. Here's the corrected
sequence:

Steps to Push a Commit to GitHub:

1. Add a remote repository:

git remote add origin https://github.com/<username>/Hello.git

2. Set global username:

git config --global user.name "your_username"

3. Set global email:

git config --global user.email "your_email"

4. Push to GitHub:

git push -u origin master

Important Notes:

 Before pushing, ensure you have made a commit using git commit -m "Your commit message".
 If your branch is not named master (e.g., main), replace master with the correct branch name.
 If authentication fails during git push, make sure you have set up your GitHub credentials, either via HTTPS
(Personal Access Token) or SSH.

You might also like