Managing Change
Repositories and Branches with CLI
Summary of Previous Session
Introduction to Version Control: Git Basics with CLI
- git init
- git clone
- git status
- git add
- git commit
- git log
What are Repositories
Local vs Remote
- Local repositories keep code separated by "project"
- Remote repositories allow us to share code
Working with Repositories
- Discuss the difference in git clone
- Show an example of the git cli command
Repository Demos
Using an existing project/repository:
# Cloning Remote:
git clone git@ssh.dev.azure.com:v3/wustl-i2/Data%20Brokers/broker-training
Creating a new project:
# Creating a Local Repository:
git init
# Adding a Remote Repository:
git remote add origin git@ssh.dev.azure.com:v3/wustl-i2/Data%20Brokers/broker-training
# Push local changes to Remote Repository
git push -u origin --all
What are Branches
- Branches hold new features or change sets
- Allows for easier collaboration
Working with Branches
git checkout
- Switching to existing branchesgit branch
- Creating and managing branches
Branches Demo
# Start from the main branch
git checkout main
# Create a new branch from main called gitSessions
git branch gitSessions
# Switch to the new branch
git checkout gitSessions
#Shortcut: git checkout -b gitSessions
# Add a new file and commit it to the new branch
echo "New file on gitSessions branch" > newfile.txt
git add newfile.txt
git commit -m "Add new file to gitSessions branch"
# Push the branch to the remote repository
git push origin gitSessions
# Show history of new branch
git log
# Compare history on main
git checkout main
git log
Merging Changes Between Branches
- Discuss the different merging strategies briefly
- Show an example of merging changes via the CLI
Merging Demo
# Switch back to the gitSessions branch
git checkout gitSessions
# Add a new file and commit it to the gitSessions branch
echo "This is another new file for gitSessions branch" > anotherfile.txt
git add anotherfile.txt
git commit -m "Add another new file to gitSessions branch"
# Switch back to main
git checkout main
# Merge the gitSessions branch into main
git merge gitSessions
Q&A and Summary
Homework
Practice branching and merging using the CLI