0% found this document useful (0 votes)
6 views5 pages

Git 004 Overview

The document provides a comprehensive overview of core Git commands essential for version control, including commands for initializing repositories, managing branches, and handling commits. It also outlines project management commands for configuring user settings and creating aliases for common commands. Each command is accompanied by a brief description and an example for clarity.

Uploaded by

John Brown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Git 004 Overview

The document provides a comprehensive overview of core Git commands essential for version control, including commands for initializing repositories, managing branches, and handling commits. It also outlines project management commands for configuring user settings and creating aliases for common commands. Each command is accompanied by a brief description and an example for clarity.

Uploaded by

John Brown
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

LANDMARK SOFTWARE SOLUTIONS

Git/Github Module –with Engr. Kah Kissinger


</> Core Git Commands </>

Core Commands:

1. git init:

 Initializes a new Git repository in the current directory.


 Creates a .git subdirectory containing configuration files and object database.
 Example: git init my_project

2. git clone:

 Creates a local copy of an existing Git repository from a remote URL.


 Example: git clone https://github.com/user/repository.git

3. git add:

 Stages changes in files for inclusion in the next commit.


 Example: git add my_file.txt

4. git commit:

 Creates a new commit with the staged changes.


 Takes an optional message describing the changes.
 Example: git commit -m "Added new feature"

5. git status:

 Shows the current state of the working directory and staging area.
 Indicates which files are modified, staged, or unstaged.
 Example: git status

6. git diff:

 Compares the current working directory with the staged changes or the last commit.
 Shows the specific differences between the files.
 Example: git diff

1|Page
7. git log:

 Displays a list of commits in the repository's history.


 Shows commit messages, author information, and commit hashes.
 Example: git log

8. git reset:

 Unstages changes or reverts to a previous commit.


 Can be used with --hard, --soft, or --mixed options to control the extent of changes.
 Example: git reset --hard HEAD^

9. git checkout:

 Switches between branches or restores files from a previous commit.


 Example: git checkout feature_branch

10. git branch:

 Creates, lists, or deletes branches.


 Example: git branch new_feature

11. git merge:

 Combines changes from one branch into another.


 Can result in merge conflicts if changes overlap.
 Example: git merge feature_branch

12. git push:

 Sends local commits to a remote repository.


 Requires a remote URL to be configured.
 Example: git push origin main

13. git pull:

 Fetches changes from a remote repository and merges them into the current branch.
 Example: git pull origin main

14. git revert:

 Creates a new commit that undoes the changes of a previous commit.


 Example: git revert <commit_hash>

2|Page
15. git stash:

 Temporarily saves uncommitted changes.


 Can be later applied or discarded.
 Example: git stash

16. git cherry-pick:

 Applies a specific commit from one branch to another.


 Example: git cherry-pick <commit_hash>

17. git rebase:

 Replays commits from one branch onto another.


 Can be used to clean up history or avoid merge conflicts.
 Example: git rebase main feature_branch

18. git tag:

 Creates a tag to mark a specific commit.


 Example: git tag v1.0

19. git remote:

 Manages remote repositories.


 Example: git remote add origin https://github.com/user/repository.git

20. git submodule:

 Includes a Git repository as a subdirectory within another repository.


 Example:

git submodule add https://github.com/user/submodule.git submodules/submodule

3|Page
</> Git Commands for Project and Branch Management </>
</s> Branch Management </s>
1. git branch -d <branch_name>: Deletes a local branch after merging it into another branch.
2. git branch -D <branch_name>: Deletes a local branch without merging it, forcing deletion.
3. git checkout -b <new_branch_name>: Creates a new branch from the current branch and
switches to it.
4. git checkout -b <new_branch_name> <start_point>: Creates a new branch from a specific
commit or tag.
5. git merge --no-ff <branch_name>: Creates a merge commit even if the merge could be fast-
forward.
6. git merge --squash <branch_name>: Combines the changes from the specified branch into
a single commit.
7. git rebase -i <start_point>: Interactively reorders, edits, or squashes commits.
8. git cherry-pick -m <parent_number> <commit_hash>: Picks a commit from a parent
branch when there are multiple parent commits.
9. git branch --force <branch_name>: Forces the branch to be updated to the specified
commit, even if it conflicts.
10. git branch --track <remote_branch_name> <remote_name>: Sets up a tracking branch for a
remote branch.
</s> Project Management </s>
11. git config --global user.name "Your Name": Sets your name globally for Git commits.
12. git config --global user.email "[email protected]": Sets your email address globally
for Git commits.
13. git config --global core.editor "your_favorite_editor": Sets your preferred editor for Git.
14. git config --global core.autocrlf true: Automatically converts CRLF line endings to LF on
checkout and LF to CRLF on commit.
15. git config --global core.editor "vim": Sets Vim as the default editor for Git.
16. git config --global color.ui true: Enables colorized output in Git commands.
17. git config --global alias.st status: Creates an alias for the git status command.
18. git config --global alias.co checkout: Creates an alias for the git checkout command.
19. git config --global alias.br branch: Creates an alias for the git branch command.
20. git config --global alias.lg log --graph --pretty=format:'%Cred%h%Creset - %s
%Cgreen(%an%Creset)': Creates a custom alias for a more readable log format.

4|Page
5|Page

You might also like