Your ultimate guide

Git & GitHub _ GitLab Setup/Commands page to post

Git - bash installation:

  • Go to "https://git-scm.com/downloads"
  • Select in Operating System you want to install this git-bash. (Windows/mac OS/linux) & download the Gib-bash executive file.

Git-bash Setup:

    When you install Git-bash, the first thing you should be doing is setting up your user details as follows only one time.

#git config --global user.name "Testing Colleges"

·        The user name no need to same as your GitHub account user name.

·        After running the command if you want to change the user name then run the same command again it will replace the exiting name.

 

#git config --global user.email "abcdefgh@gmail.com"

·        The email id which you have used in creating GitHub account that email id we have to use.

 

#git config --global –list

·        To check configuration details

 

 

 

Git1.img

Create a Local repository:

            Example: Now we are going to create a folder/directory with the name of “facebook-practice” on Desktop. And use that directory as Local repository.

·        # cd ~/Desktop

·        # mkdir facebook-practice

·        #cd facebook-practice

·        #git init : Create a local Git empty repository.

Then .git directory will automatically create on that facebook-practice directory.

 

Once we are created git empty repository it will create three logical areas:

1.     Working Area/Untracked Files

a.     Whatever the files which that are created are automatically stored in this Working area

b.     For example we are create a file “DBConnect.java” by using “#touch DBConnect.java” command.

c.      To know the status of the file, in which area the file located use “#git status” command, if the file in Red color then that files in Working Area.

2.     Staging Area/Tracked Files

a.     After file is completed on working Area then they are going to send that file into Staging Area. For that we will use following commands

                                                             i.      #git add .  : To send all file into working area to staging area.

                                                           ii.      #git add <filename1><space><filename2> : To send specific file from working area to staging area. Eg: #git add DBConnect.java Index.sh

                                                         iii.      #git add *.<extension> : To send specific extension file from working area to staging area. Eg: #git add *.java

b.     To know the status of the file, in which area it located use “#git status” command, if the file in Green color then that files in Staging Area.

3.     Local Repository 

a.     To commit the files to Staging Area to Local repository we will use following commands

                                                              i.      #git commit –m “message” : To send all files from Staging area to Local repository. Eg: #git commit –m “First commit”

                                                            ii.      #git commit –m “message” <filename1><space><filename2> : To send specific file from Staging area to Local repository.

b.     To know the status of the file, in which area it located use “#git status” command, if there are no files and displays “nothing to commit, working tree clean” then that files in Local repository area.

 

Now we need to map Remote Repository to Local Repository:

·        Go to your repository in GitHub account.

·        Select Code<> option.

·        And copy the https:// URL

·        Now go to Git Bash, and enter the following command to map remote repository to local repository.

o   Syntax: #git remote add <alias name> <https:// URL>

o   Example: #git remote add fb https://github.com/xxxxxxx/xxx.git 

·         To now which URL is map ”#git remote –v”

 

After mapping, push the files into Local Repository to Remote Repository:

·        Go to git bash and enter the following command

o   Syntax: #git push <alias name> <branch name>

o   Example: #git push fb master

§  Here master/main is a default branch name

·        When you run the above command it will ask you the GitHub credential

o   Username for ‘https://github.com’ : <enter the user name of remote repository>

o   Password for ‘https://xxxxxx@github.com’ :

§  Instead of Password we need to get the PAT (Personal Access Token).

§  To get PAT, go to GitHub

§  Click on your profile then click on Settings

§  Then click on <> Developer settings (located in left side down corner)

§  Click on Personal access token

§  Then click on Generate new token

·        Note : <give the token name>

·        Expiration : <give the expire date for this token, here we also have Never expiration>

·        Select scopes: <scopes define the access for personal tokens, select scopes>

§  Then click on Generate Token

§  Now we get PAT token Copy the token & save it somewhere, because later won’t not able see it again.

o   Past the PAT token in Password and hit the Enter key. Then it will push the files from Local repository to Remote repository.

·        < In the next time it will not going to ask the credential, these credential are stored in Credential Manager application in windows, Keychain Access in Mac if you want you can delete these Credentials there>

 

Git Flow: git init à git status à git add à git commit à git remote add à git push

 

Git and GitHub:

Git is a Version Control System, be used to develop the codes and main the versioning.

GitHub is a Hosting service, which can be used to manage the source code, it will provides the GUI.

 

Difference between Git and SVN:

Git is a Distributed Version Control System (DVCS). In this first we work on Local repository then we distribute code into Remote Repository.

SVN, CVS, and TFS are only Version Control System (VCS). It this we will directly work on Remote Repository.

 

What is Version Control System?

When developers are creating something (an application, for example), they are making constant changes to the code and releasing new versions, up to and after the first official (non-beta) release.

Version control systems keep these revisions straight, and store the modifications in a central repository. This allows developers to easily collaborate, as they can download a new version of the software, make changes, and upload the newest revision. Every developer can see these new changes, download them, and contribute.

 

Git + SVN = No

SVN client + SVN = Yes

Git + GitHub = Yes

Git + GitLab = Yes

Git + BitBucket = Yes

Git + Azure repos = Yes

 

 

            After commit, if you modify the file code in Local repository, then that modified file store in working area.

To send directly this file into Local repository use the following command:

Syntax: #git commit -a -m “message”

Example: #git commit -a -m “Updated file”

Only this command is worked for modified files

 

 

#git log : It will give all commit ids with detailed information.

#git log -2 : It will display last 2 commit ids.

#git log --oneline : It will give all commit ids without detailed information

 

#git show <commit id> : It will give details of this commit id (we can get commit id in “#git log” command)

#git show --pretty="" --name-only << Commit ID >> : It will display all the files which are committed in that particular commit.

 

To remove working area file:

#git clean -n : It will preview the changes what we are going to remove.

#git clean -f : If we want to remove new files from working area.

 

To get back the file from Staging area to Working area:

#git reset : To revert back all files to working are from staging area.

#git reset <<File Name>> : To revert back specific file to working are from staging area.

 

#git revert <<Commit ID>> : It will revert the changes committed in that particular commit id from local repo.

#git push origin master -f: It will revert the changes from remote repo.

No comments:

Post a Comment