- You can use git CLI
- You can also use other tools such as Visual Studio (through Team Explorer)
- Connect directly to Azure DevOps with your Microsoft account to work with Azure Repos.
- Create a repository
- Download
git
- run
git init
on a folder where you'll want to have your repository- You get
master
branch ready HEAD
shows the current branch in start it'smaster
- You get
- Create a file called
filename.txt
- Run
git add filename.txt
orgit add .
(for all files in the folder) - Commit your changes with a message
git commit -m "first commit"
- Download
- Useful commands
git log
: to show all commits- Each commit has
SHA
hash you can see here. - You can revert a commit using
git revert commit-sha
(or first 3 chars of thesha
)
- Each commit has
git fetch
: to download remote-tracking branchesgit pull
: doesgit fetch
followed by agit merge FETCH_HEAD
to update your files to latest in remote.
- Working with multiple developers -> Changing master branch is not good.
- Some changes may not be complete or working as it should.
- Making changes to
master
branch itself can make other developers get incorrect or non-working code.
- Instead create another branch from
master
and each developer work on their own branches- Main master branch remains intact with working code.
- You can create multiple branches
- Branches are lightweight
- Copies of your code are not made.
- E.g. separate branch for each bug fix / feature.
- In git:
- Run
git status
to see the base you're currently working from - Create new branch using
git branch <branch-name>
- Switch to the new branch using
git checkout <branch-name>
- At any point, when you want to merge your changes, you can run
git merge
- First you need to be on master
git checkout master
- Then you run
git merge feature-branch
- First you need to be on master
- Run
- Long-Running Branches
- e.g entirely stable in their
master
branch
- e.g entirely stable in their
- Topic branches
- Short-lived branches for particular feature / work
- There are usually multiple topic branches
- Progressive-stability branching
- There's only one branch
master
and everyone commits tomaster
- Good for teams transitioning from SVN.
- See also trunk-based development
- All feature development should take place in a dedicated branch instead of the
master
branch. - Logical extension of Centralized Workflow.
- Cons:
- Easy for multiple developers to work on a particular feature without disturbing the main codebase.
master
branch should never contain broken code, which is a huge advantage for continuous integration environments.- Enables PR's
- Strict branching model designed around the project release
- Based on Feature Branch Workflow
- Development:
- Feature branches are branched off of the
develop
branch - Finished features and fixes are merged back into the
develop
branch
- Feature branches are branched off of the
- Releasing:
- When it is time to make a release, a release branch is created off of
develop
. - When the release is finished, the release branch is merged into
master
and intodevelop
too
- When it is time to make a release, a release branch is created off of
- 🤗 See Gitflow animation
- 🤗 The Gitflow Workflow was first published in a highly regarded 2010 blog post from Vincent Driessen at nvie
- Based on feature branch workflow
- Enforced in Microsoft
- Development:
- Dev creates a new branch off of our main integration
- 💡 Use feature flags to have short-lived branches
- Devs push their local branch to a branch on the server, and open a pull request
- When tests are passed, changes are merged into
master
- Dev creates a new branch off of our main integration
- Releases:
- Releases always result in a tag of the repository
- A release tag should use a three segment number as defined in Semantic Versioning 2.0.0:
MAJOR.MINOR.PATCH
- If a release branch is necessary
release/1.1.x
is created.
- Each contributor two Git repositories
- a private local one and a public server-side one.
- E.g. GitHub
- Once the code is in a shared repository, a developer can clone the repository
- They can then create a branch out of the current master branch
- They then make changes on their branch
- Copy of the entire repository
- Commits do not go against the original repository
- Use-cases:
- Main repository might have issues, so clean new repository is forked for making changes
- Building application for multiple clients and each client has client-specific features
- A dev has cloned a repo > created a new branch > made changes > commited to branch > pushed branch to remote repo > wants to merge the branch into the branch.
- Developer initiates a pull-requests
- If there are conflicts between main & uploaded branch
- They need to be resolved
- Approval needs to be put into place for the pull request