What is Git
Linus Torvalds has quipped about the name “git“, which is British English slang for a stupid or unpleasant person: “I’m an egotistical b*****d, and I name all my projects after myself. First Linux, now git."
Why do you want to use Git ?
What do you want out of today ?
What's good about Git
How Git works with files
Command line interface (CLI)
GUIs exist: Atlassian source tree, Kraken, IDE (visual studio)
https://bitbucket.org/peterkaras/global-aerospaceSimple html page we can explore feature of git. Explore the Bitbucket UI...
We are using Bitbucket to host our remote repo, but we could be use:
They all provide very similar functionality
Slides - talk - discuss
Time for practice, work in groups around Laptops.
Questions, discussion...
We will practice commands as much as possible
git clone
git add
git commit
git pushIdentifies you when you are pushing changes to a shared repository
$ git config --global user.name "John Doe"
$ git config --global user.email john@test.com$ gityou are ready to go....
Creates a repository into a newly created directory: create .git folder
git clone https://bitbucket.org/peterkaras/global-aerospace.gitgit initInitialises a repository that you can later push to a shared repository
git statusCreates a repository into a newly created directory.
git clone git://sfdsfdsgit remote -vLists remote repos
You can access by providing username and password each time
HTTPSSSHYou can upload your public SSH key for easier long term access
Add your new file to the staging area.
git add .git statusCommits, creates a checkpoint with your change
git commit -m "my first change"git statusWe organise our work into commits using the staging area
What happens when everyone pushes their changes at the same time ?
git pushgit branch
git fetch
git pull
git merge
git pushCreates a new branch
git branch my-first-branchgit checkout my-first-branchMoves HEAD to point at your new branch
git status
git add .
git status
git commit -m "my change"
git statusShows you local and remote branches
git branch -agit push -u origin my-first-branchStores your branch on the remote repository
Fetches the latest view of the shared repository
git fetchgit pullfetch + merge into current branch.... see later
git checkout master
git pull
git checkout mybranch
git merge master
git commitgit checkout master
git merge another-branch
git commitWhen are you sure you can merge to master ?
Why do we need to get latest versions from master ?
[1] All create a branch and make some changes and push...
[2] One person merge to master
[3] Everyone pull latest changes and merge master to their barnches
git checkout -b my-new-branchIf you have questions, please
<<<<<<< HEAD
my text in the head
=======
the text in branch-a
>>>>>>> branch-aGit does a good job automerging, but sometimes you need to intervene manually to resolve conflicts
git push -u origin my-changesCreate a pull request and add each other as reviewers.
Why use pull requests ?
How long do you think branches should stay open ?
Whats the disadvantage of having long lived branches ?
How does this relate to user stories (items of work) ?
git commit
git log
git stash
git rebase
git revert
git tagHow does the commit history look ?
Makes commits meaningful
Can be
git commit -m "WAP-967 feature(postcode selection)"Self explanatory names
git checkout -b fb/GA-789/my-new-featureCan use convention:
Keeping organised about commits means a clean history.
1 Story = 1 commit
git loggit rebase -i <commit number>Allows you to clean up local history
Saves staged and working directory.
git stashgit stash applyreapplies stashed changes
Creates a Tag V1.4
git tag -a v1.4 -m "my version 1.4"git taglists tags
should you branch or tag ?
#remote
git push -d <remote_name> <branch_name>
#local
git branch -d <branch_name>Always delete merged branches
unstages local files
git reset HEAD .git checkout .replaces unstaged files with contents of HEAD. overwrites changes
Creates a new commit backing out those changes
git revert <commit>https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow
If you use git flow and find yourself diverging from the simple model, you are probably compensating for organizational or infrastructure issues.
git --help <command>google git manual
google atlassian gitflow
google stackoverflow
Each take one of the following changes and create pull requests then merge to development.