Quick Git Exercise from Init to Branch to Merge And Little More

Quick Git Exercise from Init to Branch to Merge And Little More

This post present a quick 15 mins exercise to play with git e.g.  from Init to Branch to Merge And Little More, and given you have a github account.

Exercise -1 : Git Init, Git Add, Git Commit, Git Remote Add, Git Remote and then Git Push

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git init
Initialized empty Git repository in /Users/eSumit/Documents/ResearchWork/.git/
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ vi example.txt
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git status
On branch master

No commits yet

Untracked files:
(use “git add …” to include in what will be committed)

example.txt

nothing added to commit but untracked files present (use “git add” to track)
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git add .
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git commit -m ” example file”
[master (root-commit) 12af50a] example file
1 file changed, 1 insertion(+)
create mode 100644 example.txt
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

git remote add <name> <url>

and then push using the remote name

git push <name>

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git remote add Research https://github.com/esumit/Research.git
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

git remote add <name> <url>

and then push using the remote name

git push <name>

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git remote add https://github.com/esumit/Research.git
usage: git remote add [<options>] <name> <url>

-f, –fetch fetch the remote branches
–tags import all tags and associated objects when fetching
or do not fetch any tag at all (–no-tags)
-t, –track <branch> branch(es) to track
-m, –master <branch>
master branch
–mirror[=<push|fetch>]
set up remote as a mirror to push to or fetch from

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git -f
Unknown option: -f
usage: git [–version] [–help] [-C ] [-c name=value]
[–exec-path[=<path>]] [–html-path] [–man-path] [–info-path]
[-p | –paginate | –no-pager] [–no-replace-objects] [–bare]
[–git-dir=<path>] [–work-tree=<path>] [–namespace=<name>]
<command> [<args>]
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git remote -f
error: unknown switch `f’
usage: git remote [-v | –verbose]
or: git remote add [-t ] [-m ] [-f] [–tags | –no-tags] [–mirror=<fetch|push>] </fetch|push>
or: git remote rename <old> <new>
or: git remote remove <name>
or: git remote set-head <name> (-a | –auto | -d | –delete | )
or: git remote [-v | –verbose] show [-n]
or: git remote prune [-n | –dry-run] <name>
or: git remote [-v | –verbose] update [-p | –prune] [( | )…]
or: git remote set-branches [–add] <name> <branch>…
or: git remote get-url [–push] [–all] <name>
or: git remote set-url [–push] <name> <newurl> [<oldurl>]
or: git remote set-url –add <name> <newurl>
or: git remote set-url –delete <name> <url>

-v, –verbose be verbose; must be placed before a subcommand

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git remote set-url https://github.com/esumit/Research.git
usage: git remote set-url [–push] <name> <newurl> [<oldurl>]
or: git remote set-url –add <name> <newurl>
or: git remote set-url –delete <name> <url>

–push manipulate push URLs
–add add URL
–delete delete URLs

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git remote add origin https://github.com/esumit/Research.git
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

git push –set-upstream origin master

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git push –set-upstream origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 228 bytes | 228.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/esumit/Research.git
* [new branch] master -> master
Branch ‘master’ set up to track remote branch ‘master’ from ‘origin’.
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$

Exercise -2 :  Create a Branch Develop, Add Files into it, an dPush code to this new Branch 

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git checkout -b develop
Switched to a new branch ‘develop’
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ ls
example.txt work/
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ mkdir work1
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ cd work1
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork/work1$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork/work1$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork/work1$ vi example2.txt
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork/work1$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork/work1$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork/work1$ cd ..
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ ls
example.txt work/ work1/
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git status
On branch develop
Untracked files:
(use “git add <file>…” to include in what will be committed)

work1/

nothing added to commit but untracked files present (use “git add” to track)
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git add .
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git commit -m “pushing to develop”
[develop 82e31d2] pushing to develop
2 files changed, 2 insertions(+)
create mode 100644 work1/1
create mode 100644 work1/example2.txt
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git push
fatal: The current branch develop has no upstream branch.
To push the current branch and set the remote as upstream, use

git push –set-upstream origin develop

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git push –set-upstream origin develop
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 343 bytes | 343.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To https://github.com/esumit/Research.git
* [new branch] develop -> develop
Branch ‘develop’ set up to track remote branch ‘develop’ from ‘origin’.
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$

Exercise-3  Merge :Develop to Master 

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git checkout master
Switched to branch ‘master’
Your branch is up to date with ‘origin/master’.
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git merge develop
Updating 12af50a..82e31d2
Fast-forward
work1/1 | 1 +
work1/example2.txt | 1 +
2 files changed, 2 insertions(+)
create mode 100644 work1/1
create mode 100644 work1/example2.txt
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$

 

Exercise-4 : Create a Feature Branch and Push some changes there 

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git branch -a
develop
* master
remotes/origin/develop
remotes/origin/master
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git checkout -b feature-231
Switched to a new branch ‘feature-231’
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ ls
example.txt work/ work1/
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ vi feature1.txt
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git status
On branch feature-231
Untracked files:
(use “git add <file>…” to include in what will be committed)

feature1.txt

nothing added to commit but untracked files present (use “git add” to track)
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git add .
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git commit -m “added feature1.txt to feature branch”
[feature-231 d5cba53] added feature1.txt to feature branch
1 file changed, 1 insertion(+)
create mode 100644 feature1.txt
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git push
fatal: The current branch feature-231 has no upstream branch.
To push the current branch and set the remote as upstream, use

git push –set-upstream origin feature-231

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git push –set-upstream origin feature-231
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 371 bytes | 371.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/esumit/Research.git
* [new branch] feature-231 -> feature-231
Branch ‘feature-231’ set up to track remote branch ‘feature-231’ from ‘origin’.
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$

Exercise -5: Merge this feature with develop branch 

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git branch -a
develop
* feature-231
master
remotes/origin/develop
remotes/origin/feature-231
remotes/origin/master
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git checkout develop
Switched to branch ‘develop’
Your branch is up to date with ‘origin/develop’.
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ ls
example.txt work/ work1/
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git merge feature-231
Updating 82e31d2..d5cba53
Fast-forward
feature1.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 feature1.txt
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git ls
git: ‘ls’ is not a git command. See ‘git –help’.

The most similar command is
log
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git status
On branch develop
Your branch is ahead of ‘origin/develop’ by 1 commit.
(use “git push” to publish your local commits)

nothing to commit, working tree clean
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git pull
Already up to date.
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ ls
example.txt feature1.txt work/ work1/
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$

Exercise-6 :  Merge Develop to Master 

eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git checkout master
Switched to branch ‘master’
Your branch is ahead of ‘origin/master’ by 1 commit.
(use “git push” to publish your local commits)
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$ git merge develop
Updating 82e31d2..d5cba53
Fast-forward
feature1.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 feature1.txt
eSumit@Sumits-MacBook-Pro:~/Documents/ResearchWork$

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s