My scrapbook about anything which I learned or want to remember, Sometime about tech tips, thoughts and rambling. If you find anything useful don't forget to give thumbs-up :)

Breaking

Monday, November 12, 2018

Let's Learn - Git Basics #2


Continuing from last post Let's Learn - Git Basics #1 where we have created the github account and a new repository. It is always a good practice to put all your code/work in one place so create a folder named something easily recognizable such as "gitCode" (in my case I have used "Git"). This will ensure that all your git code will be there for easy access.

Configuration:
Before starting to work, we will add configuration settings on our "Git" folder by executing below commands.


Check Configuration:
After setting up, you can view what your configurations look like by below commands -
=

=
=

Command to check Status:
To check the status of our work, GIT provides a command as below, It's very helpful while working with git - 
=
=
Working with new Repository:
a. We have already created a new repository on github named "git-learn", let's create a local repo as well.
==


b. After creating a local repository, we need to make it git repository by command "git init", this will create a hidden folder inside "git-learn" which holds all the changes done in local repository
=
==

c. Out git repository is ready, now let's make the first change inside it by creating a README.md file which holds the information about this repository. This is a markdown file which is used for repository documentation
==

d. After making this change, let's check the local git repo status.
==

"git status" command will display the current status of repo, Here, we can see README.md file under untracked files category (we will discuss about different type of status type later).
Untracked Files: Files about which git is not aware, as this is a new file. To push this file to remote git, we need to stage this file.

e. For staging this file, run the command as below -
==

After staging the file, we check the repo status which tells that there is a new file which has been staged to commit. But this changes hasn't been committed for push to remote repo.

f. Committing the changes is very easy and it's advisable to provide a proper comment while commit which help you in future while reviewing all the commits done on remote repo
==

g. Changes are committed, now we are good to push these changes to remote repository. But before that, as this is a new local repository, we need to tell this to which remote git repository it should commit to, Hence run the below add command, you have to run this command once per repository, so from next commit, no need to run this command unless you want to change the remote repo url.

When you push the local changes to remote, it will ask your github credentials as below (push will ask github credential every time which can be annoying and can be avoidable by setting up ssh keys with github account)
==

h. After entering github credentials, it will start pushing the data to remote git repo. 


i. When push is complete, we can check the current repo status as above.
j. You can view all the commits have been done on repository by "git log" command
==


In next post, we will see the type of changes done in git repository and how to setup password-less git repository.
Till then, Keep Loving this Blog .......... Happy Learning...........



Like the below page to get update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


Disclaimer

The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.