Git and Bitbucket
- What are Git and Bitbucket?
- Installing the Git repository tool in the local machine
- Creating a project in bitbucket and adding users to the respective project in Bitbucket
- Configuring user credentials in developer machine
- Creating development projects and connecting with Bitbucket
- Managing Git branches and keeping track of different versions
- Add changes to the remote repository
- What is .gitgnore?
1 — What are Git and Bitbucket?
Git
- Git is a distributed repository management tool (version control tool).
- It contains a set of commands in order to manage the project repository.
Bitbucket
- Bitbucket provides a service to host the repository in the cloud/physical server that configures Bitbucket.
Git and Bitbucket work together in order to manage the repository
2 — Installing the Git repository tool
Click download and install — https://git-scm.com/
3 — Creating a project in bitbucket and adding users to the respective project in Bitbucket
- Sign up or Log in to the bitbucket account.
- Create a project and repository.
- Adding users who will work in the repository with permissions.
4 — Configuring user credentials in the developer machine
open the git bash and follow the commands,
note: Use the user name and email which were integrated with Bitbucket.
git config — global user.name ‘user_name’
git config — global user.email ‘user@testmail.com’
To see all the global parameters: git config — list
5 — Working with the remote repository(clone repo)
after the Git bash opens the following steps in the bash,
i - clone the repository to that folder.
git clone https://user@bitbucket.org/user/test_repo.git
If you facing any authentication issues, watch this video.
Managing Git branches and keeping track of different versions
6 — Managing Git branches and keeping track of different versions
Note: The default branch is the master.
Optional steps are done by the project admin,
i — Create a new branch
note: change the directory (cd test_repo) into the git repository that was cloned.
git branch br_dev1
- in the project, each developer has their own branch which is used to push changes in the project that was done by the specific developer.
- When we create a new branch from a previous branch, it takes the copy of the previous branch. for example, in our case we create a new branch br_dev1 from the master branch, therefore br_dev1 branch takes the copy of the source code from the master branch.
ii — Switch into the created branch
git checkout br_dev1
ii i— Initialized the created branch in the remote repository.
- Every branch has two copies of the branch.
a— local copy/repository (master, dev1) — The version maintains in the local machine
b — remote copy/repository (remotes/origin/master) — The branch maintains in the remote server.
- It is important for which branch is updating work with the project.
git push -u origin br_dev1 — create br_dev1 in the remote repository and push everything in the local branch into the remote branch.
7 — Add changes to the remote repository.
now I’m in the br_dev1 branch.
i — Make changes in existing files from local the machine.
ii — git status
- show all the changes.
- in our case add, and modify files available in the local project file(local uncommitted changes) not in the br_dev1 branch.
iii — git add .
- adding those changes to staging area.
iv — git commit -m “this is my first commit”
- commit all the changes into the local repository of the particular branch(br_dev1 branch).
v — git push
- push all the changes in the local repository into the remote repository of the particular branch(br_dev1 branch).
vi — merge the changes that are available in the remote repository of the particular branch(br_dev1 branch) into the master branch.
- git checkout master — first, switch to the master branch.
- git merge origin/br_dev1 — merge local master branch from changes available in remote br_dev1 branch
- git push — push all the things available in the local master branch into the remote master branch
8 — How next developer get the updated code form repository?
i — git clone https://user@bitbucket.org/user/test_repo.git
- clone the repository of the particular project into a particular local directory (one time enough).
ii — navigate into the respective cloned project
iii — git branch br_dev2
- create a new branch done by admin (one time enough)
iv — git checkout br_dev2
- switch into particular branch
v — git push -u origin br_dev2
- create br_dev2 in the remote repository and push everything in the local branch into the remote branch.
vi — git pull origin master
- Pull the update from the master branch