So wanted to tryout as I had heard a lot about GIT.
I am still learning about GIT this an initial doc to have anyone to get started.
Before you start, I recommend you to go through the video below.
Few command you will see which are commonly used.
$ git init - Initialize GIT repository
$ git status - show status of the repository - modified files etc
$ git add - Adds file/directory to staging area (ready for commit/check-in
$ git reset - removes file from staging area (not ready for commit) - changes to file will not be affected.
$ git commit - Commits data to repository (LOCAL repos)
$ git push origin -all - Push data from LOCAL repos to SERVER repos
$ git clone - Pulls data from SERVER to LOCAL repos
Setting up GIT Server
- create a directory
ahmed@ahmed-work-horse:~/Desktop$ mkdir testGitProject
ahmed@ahmed-work-horse:~/Desktop$ cd testGitProject/
ahmed@ahmed-work-horse:~/Desktop/testGitProject$ pwd
/home/ahmed/Desktop/testGitProject
- Next let create a git respos - server.
- You will see all the information, (similar to as we see in svn server repos - Yes I am a SVN guy).
ahmed@ahmed-work-horse:~/Desktop/testGitProject$ git --bare init
Initialized empty Git repository in /home/ahmed/Desktop/testGitProject/
ahmed@ahmed-work-horse:~/Desktop/testGitProject$ ls -a
. .. branches config description HEAD hooks info objects refs
Setting up client and pushing into GIT Server
- Setting GIT config information - Not very important but its good to have this.
ahmed@ahmed-work-horse:~/ahmed$ git config --global user.name "ahmed"
ahmed@ahmed-work-horse:~/ahmed$ git config --global user.email "ahmed@saggezza.com"
ahmed@ahmed-work-horse:~/ahmed$ git config --global color.diff auto
ahmed@ahmed-work-horse:~/ahmed$ git config --global color.status auto
ahmed@ahmed-work-horse:~/ahmed$ git config --global color.branch auto
- Lets Create a git repos locally (and later we will link this to our server).
ahmed@ahmed-work-horse:~/ahmed$ cd testGitProject/
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ ls
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ git init
Initialized empty Git repository in /home/ahmed/ahmed/testGitProject/.git/
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
- As you can see this is an Empty Repositoty.
- Lets create file readme.txt and add this to the respoitory.
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ vim readme.txt
- Now you can see below once we have a file - but this is not add or committed to GIT.
- we need to do this so that GIT will take care of version control.
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# readme.txt
nothing added to commit but untracked files present (use "git add" to track)
- Now lets add this file to repos.
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ git a
add am annotate apply archive
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ git add readme.txt
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: readme.txt
#
- Once we add, file goes into a staging area, you can call this as ready to commit.
- But still the file is not commited.
- Now lets do that next.
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ git commit readme.txt
[master (root-commit) 6bf4daf] First Document !!
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 readme.txt
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ git status
# On branch master
nothing to commit (working directory clean)
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ ls
readme.txt
- Once we have commit you will see.
- Number of files changed, number of lines updated/added, and number of files deleted.
Linking client repos to the server.
- Now lets link the client repos which has the update to server.
- Once we are done with this we can push (check-in to the server in SVN terms) data to server.
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ git remote add origin ssh://ahmed@172.16.2.15/home/ahmed/Desktop/testGitProject
ahmed@ahmed-work-horse:~/ahmed/testGitProject$ git push origin --all
ahmed@172.16.2.15's password:
Counting objects: 2568, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2506/2506), done.
Writing objects: 100% (2568/2568), 32.02 MiB | 4.05 MiB/s, done.
Total 2568 (delta 859), reused 0 (delta 0)
* [new branch] master -> master
- Lets analyse the first line here.
- git push origin --all This will push all the data into the server.
- we are connecting to GIT server over SSH.
Testing the sever - if all izz well !!
- Lets create a new directory and clone the respository (checkout in terms of SVN).
ahmed@ahmed-work-horse:~/ahmed$ mkdir testServerInformation.git
ahmed@ahmed-work-horse:~/ahmed$ cd testServerInformation.git/
ahmed@ahmed-work-horse:~/ahmed/testServerInformation.git$ ls
ahmed@ahmed-work-horse:~/ahmed/testServerInformation.git$ git clone ssh://ahmed@172.16.2.15/home/ahmed/Desktop/testGitProject
Cloning into testGitProject...
ahmed@172.16.2.15's password:
remote: Counting objects: 2568, done.
remote: Compressing objects: 100% (1647/1647), done.
remote: Total 2568 (delta 859), reused 2568 (delta 859)
Receiving objects: 100% (2568/2568), 32.02 MiB | 24.71 MiB/s, done.
Resolving deltas: 100% (859/859), done.
ahmed@ahmed-work-horse:~/ahmed/testServerInformation.git$ ls
testGitProject
ahmed@ahmed-work-horse:~/ahmed/testServerInformation.git$ cd testGitProject/
ahmed@ahmed-work-horse:~/ahmed/testServerInformation.git/testGitProject$ l
readme.txt
- Lets analyse the first command.
- git clone ssh://ahmed@172.16.2.15/home/ahmed/Desktop/testGitProject
- we are connecting to GIT server over SSH.
- As you can see we see same respose been pulled out from the server (check-out).
- Terms in GIT -- push to sever (check-in) and pull to server (check-out).
- Please make sure that the GIT server accepts SSH connections.
- To test this just do something like ssh ahmed@172.16.2.15 - this should log-you-in into the server
Getting GIT from GIT
Thats it for now.
I will update this as I learn more information about GIT .. :)
Happy Coding !!
Comments
Post a Comment