Git and Github Basic Commands - Tecnew

Home Ads

Git and Github Basic Commands

Git and Github Basic Commands

Share This

 

Git (Version Control System)

Git: Git is a version control system (It is used to maintain a version control tracking)

If you change any files edit and saved and make some modifications and save it again and it stores and takes back up and it will take again from back up this is a long process to do these all the tasks will do a tool is called 

Version Control System it has own mechanism to do or maintain the versions and maintain all the history.

For Individual Help:It is helpful to revert back to the previous versions and new versions and it like a “time machine” like where you want to go the changes have done earlier and previous stages

For Working with Team: It differences the current work, add the contents and merging changes

Management of Changes to Files: It maintains the track changes have occurred and it allows to people work together with any kind of text data it can track the changes

Localized and Centralized VCS

Localized VCS means using individually using in the local system and working on those files modifications and changes

·       Centralized VCS having the server where the master repository kept and users having the copy of the repository

Centralized VCS:

·       In Subversion, CVS, Github Have a central repository complete copy having the server all the history will save the server

·       You make local modifications you check out to your local system and make modifications and check-in back to the server

 Drawbacks:

·       In both approaches in local tool fail the local fails, in centralized if the server fails no commits are performed into the central server to over cum these drawbacks

Distributed version control system:

·       In distributed VCS have a local copy and master copy both are same you made changes at local system only after changes are done after commit and push into the server it is a combination of localized and centralized VCS.

·       Here server is used to store the all the information

 Installing Git:

·       In Window install Gut Bash

·       In MacOs install via HomeBrew

·       In Linux install via the package manager (yum, apt, snap, etc)

After installing the git bash in windows open the git bash terminal

Git Commands:

mkdir skylab                                                    It makes the directory named by skylab

cd skylab                                                         It enters in to the directory skylab

git init                                                             It initialized the empty git repository

ls   -a                                                                It shows the .git files

cat   .git/config                                                It shows the configuration file contents

touch    filename                                            It will create the new files

git   status                                                       It shows the changes have to track or known

git   add   .                                                       It considering or adding to staging area

git   status                                                       It shows the status

git   commit   -m   “Comment or message”    It commit the all the changes

enter the global user and email by

git   config   --global   user.email     “name@gmail.com”       It set the email

git   config   --global   user.name    “name”                            it set the name

git   log                                                To show the changes along the commit id

 git   log   --oneline                                          It shows simple small commit id details

git   show   commitId                                      shows details if changes done adding lines

git push --set -upstream origin dev --It will create a branch in central repo with name dev and pushes the files in to that repo

git push origin --delete dev --It will delete the dev branch in remote

git branch -d dev --ut will delete the branch dev in local


already have a github account you run the below command to add the github link

git  remote  add  origin  https://github.com/yourRepository pat/repositoryname.git

Above link is your github repository link:

git   clone   https://github.com/yourRepository pat/repositoryname.git

cat   .git/config                                                It shows the remote repository info

git   branch   -M   main                                   It changes the branch name master to main

git   push   -u   origin   main                            It pushes to all the info from local to remote

git   pull                                                           It pull the all changes from remote to local

Create Branches:

git   branch   -c   branchName                         Create branch and copying the contents from main branch      

git   checkout   branchName                           To enter in the branch from main

git   branch   -a                                                To show all the branches you have

git   rm   file                                                     To remove file and also remove from staging area also

git   mv                                                            is move command

git   push   origin   sprint1                               It create a file name sprint1 branch name in central and pushes the files

Also, you create branches at github gui

git   checkout   sprint2                                    Enter in to sprint2 branch

Once checkout you can also switch the branches line

git   switch   main

git   switch   sprint1

sit   switch   sprint2

Merge branches:  first you enter in to the main branch after you merge the which branch you need with

git   merge   sprint1                                        It merge sprint1 branch with main branch

git   push   -u   origin   main                            It pushes it to remote

 

No comments:

Post a Comment