Exploring Git

Git is an open source DVCS that manages set of files as they change over time.

How is it different from centralised VCM?

A DVCM is secure as multiple users can push the code easily as they get copies of repos. If you lose backups, dealing with CVCM becomes a nightmare. Here lies the power of using Git.

Why Git?

Commands

To start from scratch, goto the directory where you want to work with your project in the terminal (Mac), and then start using Git commands given below as and when required.

For remote repos

git clone https://github.com/hasura/git-push-template.git

2. To make changes live, push the code to the repo. -u in the following command, remembers what to push and where. You need not enter these details again and again

git remote add origin https://github.com/hasura/git-push-templates.gitgit push -u origin master

3. Pull requests let you tell others about changes you’ve pushed to a repository on GitHub. For pull request run git pull origin master or

git pull origin master --allow-unrelated-histories

4. To see changes in commits, i.e. from previous commit to the latest, run git diff HEAD.

Branching

If you make some changes and commit again, the next commit stores a pointer to the commit that came immediately before it. A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is master.

Merging

Merging is used to merge the branches so that all the changes you made comes to live at once.

git merge -a -m 'changes made'

-a in the above is used to skip the staging step. However, any new files that are untracked must be manually staged using git add <filename>

Merge master into new branch

git merge master

This may arise an error saying CONFLICT. This can be resolved manually by going to the file and editing it. Fix this by deleting

<<<< HEAD
.....
.....
>>>> master

This can be fixed using tools like ‘tortisemerge’ tool or ‘winmerge’ tools. Firstly install these tools and then try running git mergetool

Learn more on https://try.github.io/ and http://gitreal.codeschool.com/

In Short:

cd repository
git branch new-branch
git checkout new-branch
git checkout master
git add -A
#push to new branch
git push --set-upstream origin new-branch
git remote -v
git remote add upstream https://github.com/TejasReddy9/sec_bichromaticds.git
git remote -v
git fetch upstream
git checkout master
git merge upstream/master

UP NEXT

Hasura local development setup

Consultant