- Git is a distributed open-source version control system (VCS)
- Applications:
- Solo Project
- Class project
- Overcome Your Fear Boot Camp projects
- Workplace
- Git is free and easy to install on Linux, Windows and MacOS.
- Link to use to install
We need to configure git so it identifies us when we create our versions, and when we push them to remote repositories.
- git config --global user.name "Peter Mutisya"
- git config --global user.email [email protected]
What is a repository? Refers to a 'project' in git. It tracks the versions of all changes made. It also keeps metadata. This info goes into a .git folder in the repository folder. Local Repository: Exists on your laptop Remote repository: Exists on a VCS server like Github, Bitbucket, Gitlab. To initialize a local repository: git init To initialize a remote repository, you can use ui controls.
- Staging: Files that are tracked, that is they will be part of the next version.
- Unstaged changes: These are changed on the working directory which are not yet staged.
- To get a remote repository to your local machine, run:
git clone <url> <destination folder - Optional>
git status
: Gives you information about your current branch. A branch is a line of development.git add <file or folder>
: To include the file(s) into the staging area.git commit
: To add staged changes to a version. This serves as a checkpoint in our project which we can always come back to.git log
: To see history of commits/versions.git checkout <commit hash>
: To go back to a certain commit.git revert
: Go back to the past commit.
git pull
: get and apply updates from remote repository. This is actually two commands in one.git fetch
: Get updates from remote repogit merge
: Apply changes to the local repository.
- A branch is a line of development.
git branch
orgit branch --list
: : Show current branchgit branch branch-name
: Create branch named branch-namegit branch -d existing-branch
: Delete existing-branchgit merge destination-branch
: integrates or applies changes from the current branch to destination-branch.
- A pull request is a feature of many remote VCS solutions. It allows you to tell others what that you have made some changes, and they can see the changes made. Discussions can follow up.
- Once the users are satisfied with your changes, they can allow you to merge the branch (accept your changes into the team's branch).
- You are encouraged to take the review process seriously.
- Conflicts ensure where there is a clash of versions. E.g your changes and the changes of your team mate collide. There are 3 ways to resolve a conflict.
- Pick the first person's changes and ignore the second's.
- Pick the second person's changes only and ignore the first's.
- Create a new change which is a combination of both. This is the preferred approach, and is commonly done as a manual process.
How to avoid conflicts. It's worth noting that conflicts waste a lot of time, and can bring a lot of errors to a project. Features can be lost midway. To avoid conflicts:
- Share work well in such a way that multiple people are not working on the same files.
- In case you are working on the same file, do so with small commits, pushes and pulls. This reduces chance of conflicting.
- How do we create our branches and how do we name them?
- Branch names need to be descriptive of what is supposed to be done. E.g adding-api-users
- Git repositories are created with a default branch. This branch is commonly called
master
ormain
. - Some developers also create a new branch commonly called
develop
which is the destination branch for development work. - branches can also be prefixed to explain the nature of the task in question. This makes your branch intuitive. The most common branch prefixes used include:
- feature: e.g
feature/create-users
- bugfix: e.g
bugfix/users-not-able-to-log-in
- hotfix: Refers to deliver a quick fix in production. e.g
hotfix/kafka-failing
- release: Refers to a version delivered to the users. e.g
release/5.7.2
A good branching policy helps improve issue traceability and prevents conflicts.
- Most of the software planning is done outside the branches. For this,w e use issue tracking solutions such as Jira, Bitbucket issues and Github issues.
- Here is where discussions happen.
- When messaging your commits, please use descriptive names. A commit message should explain what you've done, not what you expected to do or what you wanted to achieve. Be direct.
- Also, consider using multiline messages.
This stores your credentials in memory when you're working so you don't have to keep typing your credentials.
- git config credential.helper
- git config credential.helper cache --timeout
- Keep your changes save until you need them
git stash
: To save changes in a local storegit stash pop
: To get back saved changes.- Remember this is a stack (pop). So if you do stash1, then stash2, then stash3, pop1 will give you stash 3, pop 2 stash 2 and pop3 stash 1.
- Also, stashes are not depended in the branch. So you can stash, checkout to another branch, then pop your stash.
https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/
- A simple, yet very powerful markup language. You can use it to add format to plaintext.
- You will be needed to use it to write your Readme.md file.
- This is a way of implementing CI/CD. It incorporates VCS, collaboration and compliance to service automation.
Truth be told, there is more to git. We've just talked about what you need for dy-to-day operations.