You are on page 1of 3

Git Basic Usage

Installation
Download and install git for your OS (Windows, Linux or Mac OS X)
https://git-scm.com/downloads
Open a command line prompt and run:
$ git --version
Set up an SSH key
1. Set up your default identity
$ ssh-keygen
$ ls ~/.ssh

2. Add the public key to your Bitbucket settings


Go to Bitbucket > Bitbucket settings > Account settings > SSH keys
$ cat ~/.ssh/id_rsa.pub

Configure your global Git account.


Open a command line prompt and run:
$ git config --global user.name "First_Name Last_Name"
$ git config --global user.email username@email.com

Testing your SSH connection


$ ssh -T git@bitbucket.com

Feature Branch Workflow


Open a command line prompt.
1. Start with the master branch
This workflow helps you collaborate on your code with at least one other person. As long as your
GitHub and local repos are up-to-date, you're ready to get started.
$ cd <USER_HOME> (e.g. /home/ubuntu/at10 )
$ git clone git@bitbucket.org:devops_at10/fa_repo.git

2. Create a new-branch
Use a separate branch for each feature or issue you work on. After creating a branch, check it out
locally so that any changes you make will be on that branch.
$ cd <USER_HOME>
$ cd fa_repo
$ git checkout -b feature

3. Update, add, commit, and push changes


Work on the feature and make commits like you would any time you use Git. When ready, push your
commits, updating the feature branch on GitHub
$ cd <USER_HOME>
$ cd fa_repo
$ git add .
$ git commit -m "Adding a change from the feature branch."
$ git push origin feature

4. Get your code reviewed


To get feedback on your code, create a pull request in GitHub. From there, you can add reviewers and
make sure everything is good to go before merging.
5. Resolve feedback
Now your teammates comment and approve. Resolve their comments locally, commit, and push
changes to GitHub. Your updates appear in the pull request.
6. Merge your pull request
Before you merge, you may have to resolve merge conflicts if others have made changes to the repo.
When your pull request is approved and conflict-free, you can add your code to the master branch.
Merge from the pull request in Github.

Forking Workflow
Fork the repository
A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes
without affecting the original project.
Fork your repo from https://bitbucket.org/jala_devops_02/fa_repo

All of these personal public repositories are really just a convenient way to share branches with other
developers.
Everybody should still be using branches to isolate individual features, just like in the Feature Branch
Workflow and the Gitflow Workflow.
In the Forking Workflow, they are pulled into another developer’s local repository, while in the Feature
Branch and Gitflow Workflows they are pushed to the official repository.
Syncing a fork - Configure a remote for a fork
1. List the current configured remote repository
$ git remote -v
2. Add new remote upstream repository that will synced with the fork

$ git remote add upstream


git@bitbucket.org:jala_devops_02/fa_repo.git
3. Fetch the branches
$ git fetch upstream
4. Check out your fork’s local master branch
$ git checkout master
5. Merge the changes from upstream/master into your local master branch.
$ git merge upstream/master
6. Push the changes to your fork
$ git push origin master

Basic Git command reference


Ø $ git config - Configure Git
Ø $ git init - Initialize Git repository
Ø $ git clone - Create an empty Git repository
Ø $ git status - Check the status of a Git repository
Ø $ git add - Track files
Ø $ git commit - Commit tracked files
Ø $ git push - Upload files
Ø $ git pull - Download files
Ø $ git log - Display commit history
Ø $ git switch -Switch branches

References
Ø https://git-scm.com/docs
Ø https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html
Ø https://confluence.atlassian.com/bitbucketserver0414/workflow-strategies-in-bitbucket-server-
895367612.html#WorkflowstrategiesinBitbucketServer-CentralizedWorkflow
Ø https://www.atlassian.com/git/tutorials?_ga=2.119128393.1783786947.1564496731-
1459781296.1564189717
Ø https://www.atlassian.com/git/tutorials/git-forks-and-upstreams
Ø https://www.atlassian.com/git/tutorials/git-forks-and-upstreams

You might also like