Git Operations
Git Operations
syntax.
Explanation: Creates a new Git repository in the current directory. This is done only once for
each project.
Syntax:
git init
Command:
Explanation: Sets your username and email for Git commits globally (for all repositories on your
system).
2. Adding Files
Explanation: Moves changes from the working directory to the staging area. You can specify
individual files or use . to add all changes.
Syntax:
Explanation: Saves the staged changes to the repository history with a message describing the
changes.
Syntax:
Explanation: Shows the status of changes, indicating staged, unstaged, and untracked files.
Syntax:
git status
Syntax:
git log
Explanation: Creates a separate branch to work on features independently from the main
branch.
Syntax:
Syntax:
Merge branches
Explanation: Integrates changes from one branch into another (usually merges a feature branch
into the main branch).
Syntax:
git checkout main # Switch to the branch where you want to merge
git merge <branch_name> # Merge the specified branch into the current branch
6. Remote Repositories
Explanation: Connects your local repository to a remote server like GitHub or GitLab.
Syntax:
Syntax:
Explanation: Fetches changes from a remote repository and merges them into the current
branch.
Syntax:
7. Cloning a Repository
Syntax:
8. Discarding Changes
Discard changes in a file
Explanation: Reverts changes in a specific file back to the last committed state.
Syntax:
Unstage changes
Explanation: Removes files from the staging area but keeps changes in the working directory.
Syntax:
9. Reverting Commits
Undo a commit
Explanation: Creates a new commit that reverses the changes made by a specific commit,
preserving history.
Syntax:
Each of these commands can help you efficiently manage your Git repositories in a Linux
environment.