graph TD;
A[Initialize Repository] --> B[Clone Repository];
B --> C[Check Git Status];
C --> D[Staging and Committing];
D --> E[Creating & Switching Branches];
E --> F[Merging Branches];
F --> G[Undo Last Commit];
G --> H[Stashing & Restoring];
H --> I[Rebasing Branch];
I --> J[Resolving Merge Conflicts];
graph TD;
A[Empty Directory] -->|git init| B[Git Repository Created];
B -->|echo '# My Project' > README.md| C[README.md Added];
C -->|git add README.md| D[Staged File];
D -->|git commit -m 'Initial commit'| E[First Commit];
mkdir my-git-project && cd my-git-project Initialize a Git repository and make the first commit.
git init
echo "# My Project" > README.md
git add README.md
git commit -m "Initial commit" git status # Should show a clean working directory
git log --oneline # Should show the initial commit graph TD;
A[Remote Repository] -->|git clone| B[Local Copy];
Create a remote repository on GitHub/GitLab.
Clone the repository locally.
git clone <repository-url> ls -la <repo-name> # Should list all files
cd <repo-name> && git status echo "Some content" > file.txt Check the status of your working directory.
git status Git should show file.txt as untracked.
graph TD;
A[Create file1.txt] -->|git add file1.txt| B[Staged];
B -->|git commit -m 'Added file1.txt'| C[Committed];
echo "Hello, Git!" > file1.txt
git add file1.txt
git commit -m "Added file1.txt" Make another change and commit it.
echo "New content" >> file1.txt
git add file1.txt
git commit -m "Updated file1.txt" git log --oneline -n 2 graph TD;
A[main branch] -->|git checkout -b feature-branch| B[feature-branch];
git checkout -b feature-branch Confirm that you've switched branches.
git branch # Should list 'feature-branch' and 'main'
git checkout main graph TD;
A[main branch] -->|Create new branch| B[feature-branch];
B -->|Merge back| A;
git checkout -b new-feature
echo "Feature work" > feature.txt
git add feature.txt
git commit -m "Added feature.txt"
git checkout main Merge new-feature into main.
git merge new-feature
git branch -d new-feature git log --oneline --graph graph TD;
A[Last Commit] -->|git reset HEAD~1| B[Unstaged Changes];
echo "Temporary change" > temp.txt
git add temp.txt
git commit -m "Temporary commit" Undo the last commit but keep changes.
git reset HEAD~1 git status graph TD;
A[Uncommitted Changes] -->|git stash| B[Changes Stashed];
B -->|git stash pop| A;
echo "Work in progress" > wip.txt
git add wip.txt Stash changes, switch branches, and restore them.
git stash
git checkout main
git checkout -b another-branch
git stash pop ls graph TD;
A[main branch] -->|Rebase| B[feature-branch Rewritten];
git checkout -b rebase-branch
echo "Rebase test" > rebase.txt
git add rebase.txt
git commit -m "Added rebase.txt"
git checkout main
echo "Main branch update" > main.txt
git add main.txt
git commit -m "Updated main"
git checkout rebase-branch Rebase rebase-branch onto main.
git rebase main git log --oneline --graph graph TD;
A[main branch] -->|Conflicting changes| B[feature-branch];
B -->|Merge Attempt| C[Conflict];
C -->|Resolve & Commit| D[Merge Completed];
git checkout -b conflict-branch
echo "Hello" > conflict.txt
git add conflict.txt
git commit -m "Created conflict.txt"
git checkout main
echo "Hello, World!" > conflict.txt
git add conflict.txt
git commit -m "Updated conflict.txt in main"
git checkout conflict-branch Merge main and resolve conflicts.
git merge main
# Manually resolve conflicts in conflict.txt
git add conflict.txt
git commit -m "Resolved conflict" git log --oneline --graph