Git basics

20
Basics of GIT Ashwin Date Durgesh Sonawane

Transcript of Git basics

Page 1: Git basics

Basics of GITAshwin Date

Durgesh Sonawane

Page 2: Git basics

DO GIT like a BOSS !!

Fearकडून

confidenceकडे

Page 3: Git basics

Why GIT ?

Ashwinedited

my files !!

Page 4: Git basics

Github/Gitlab - Ab Bitbucket kidhar se aya ?- Github and Bitbucket are cloud based

repository hosting services. Similar to web servers, GIT servers store your repository and allow SSH & HTTP connection

- Gitlab is a self hosted service. We’re hosting it on Amazon

- A “REMOTE” GIT repository can live anywhere - Remember it used to be on our old 192.168.1.200 server ?

Page 5: Git basics

GIT is *Distributed* Version Control- Durgesh’s Local Copy

(Durgesh’s Clone)

- Sachin’s Local Copy (Sachin’s Clone)

- Nidhi’s Local Copy (Nidhi’s Clone)

- GIT Server (Remote)

- No Need to be online to “COMMIT”

Page 6: Git basics

Remote pe Charcha- Any GIT server can be added

as a “REMOTE”

- You may add multiple “REMOTE”s to your local repository

- You “COMMIT” changes to a local clone and “PUSH” changes to a remote

Page 7: Git basics

Making a Fork- Fork is a copy of someone

else’s repository created under your own account

- You “PUSH” to your own fork and then ask the original repository owner to merge your changes

TIP : Your fork needs to be updated by pushing the changes from the original repo, it won’t update itself :)

Page 8: Git basics

Clone and get going!- Cloning will create a “CLONE” of

your remote GIT repository on your computer

- The remote GIT repository is auto configured with the name “ORIGIN”

- You can then add additional REMOTEs with other names

- If your repository is a fork, then add a new remote named “UPSTREAM” pointing to the original repo that you forked from

- git clone [email protected]/joomla/joomla-cms.git

Page 9: Git basics

Getting started with development- Once you clone start making changes to your files

- git add <file path>

- git rm <file path>

- This adds your new and changed files to the list of files that will be committed

- You haven’t committed yet

- Deleted files *also* need to be committed

- You haven’t committed yet

- This adds your changes to the list of files that will be committed

- git status

- Now is when you commit

- git commit -m “Finally, I can commit”

Page 10: Git basics

तुका म्हणे|| commit म्हणजे push नव्हे ||

- git push origin master- This will push your

files to the remote GIT repo named origin (your fork)

Page 11: Git basics

Getting other people’s changes- You’re not the only one making

commits and pushing

- Remember Sachin and Nidhi also cloned

- They also saw this and pushed

- To get their changes

- git pull origin master

- What if they changed the same files that I worked on ??

Page 12: Git basics

तुका म्हणे

|| conflict ला भि�ऊ नकोस ||

|| file बघून करशील merge ||

Merge conflicts will happen when you edit the same piece of code in the same file that someone else has worked on

You simply need to open the file and manually merge the conflicts

Page 13: Git basics

MERGE CONFLICTS are normal

Page 14: Git basics

When you have leftover, uncommitted work

Page 15: Git basics

तुका म्हणे

|| conflict ला भि�ऊ नकोस ||

|| file बघून करशील merge ||

Merge conflicts will happen when you edit the same piece of code in the same file that someone else has worked on

You simply need to open the file and manually merge the conflicts

Page 16: Git basics

Tagging in GIT- Tags are used to “Tag” releases so that the state of files against that

tag get locked, and can be referred in the future

- git tag v5.0

- git push --tags

- git pull --tags

Page 17: Git basics

GIT Gotchas- git config core.fileMode false

Ignores chmod changes from being tracked in GIT

- Use the .gitignore fileThis will stop images, backups from being committed and pushed

- Undo git addgit reset <file path>

- Reverting all changes to a file to the the latest commit

- git checkout <file path>

Page 18: Git basics

GIT Best Practices- git pull

- Pull other people’s changes frequently to stay updated

- No temporary work on masterUse branches to work on temporary stuff, don’t pollute your master branch

Page 19: Git basics

Working with Multiple REMOTEs- Useful when you are working on your own “FORK”

- git remote add upstream <git repo URL>

- upstream is the name of the remote server

- You can name it anything you want :)

- git push upstream master

- Pushes your changes to the upstream remote GIT server

- git push origin master

- Will push your changes to the origin remote GIT server

- REMEMBER - commit is always a local activity

Page 20: Git basics

Any Questions ???