Git Essentials for Developers : Distributed-is-the-new-centralized
Some of the basics command which we use daily in our development cycle.
- init
- clone
- add
- commit
- push
- pull
Few more is used for advance user who is reviewer or in the team of DevOps
- branch
- merge
- tag
These are the few but if you want to be learn more about Git suggest you to refer official URL https://git-scm.com/docs
A very good image representation we found which help you to understand Git-Architecture
Start from beginning.
- We need to install Git for your respective operating system it’s free download https://git-scm.com/download
- Register yourself to git or bit bucket repository , best thing both are free with some extent , But no worries if you are going to use for learn it’s absolutely free. if you are already register you can skip this step
To register with github follow the instruction at URL https://github.com/join
To register with bit bucket follow the instruction at URL https://bitbucket.org/account/signup/
3 . open git bash (Here i am using windows 10)
You will get the below git command line prompt , you can check your current working directory use command pwd almost all Linux command work here on this command line. you can change your directory using cd
I have used below command to reached my working directory which is under d:\medium\git
cd d:
cd medium
cd git
Now I want to clone a java project which on bit bucket. I will use bit bucket here same command you can use for git hub
Below 3 command is essential to setup a local git repository and configuration.
git init
git config user.name “[Your Name]”
git config user.email “[your email which is register with git hub or bit bucket]@gmail.com”
Now to clone the existing repository , go to you bit bucket account . you will find all the project under your account displayed . now click on the project you want to clone . then click on source , you will find the clone URL as below image copy that URL.
Now paste it at your bash command prompt and hit enter if asked for credential just enter the valid credentials
That’s it , now you have your git project ready in your working folder
Add your file inside test project and play with git command for example here creating one file and push to repository.
cd test
pwd
touch Test.java
if you are familiar with vi command you can edit from here or open in your favorite editor . write your code and save.
Use the git status
above command lists all the files that have to be committed
Then we use git add * or you can use git add . as well if want to add all the file . But if you want use only one file you can use git add [file]
above command adds one or more to the staging area.
Now commit to the local repository
git commit -m “[ Type in the commit message]”
Now push to the remote repository
git push
Now to verify you can logon to your bit bucket or git hub and check the commit you will find your file and changes
To get the latest changes before start your work as this is part of every developer life , use git pull to avoid major conflict while commit.
Hope you like it . please comment :)