21 January, 2024

Git common commands:

 

Git common commands:

Setup a username for a repository

Syntax: git config --global user.name “username”

Set up user-email for your repository

Syntax: git config --global user.email useremail@example.com

Select or create the directory where you want to initialize Git

Initialize Git in the directory Syntax: git init

To add a file to the staging area Syntax: git add <filename>

▪ To check the working tree status Syntax: git status

 

 

To commit the staged files to your local repository: Syntax: git commit

Remote Repositories:

Sign-up at github.com & Click on New repository to create a new repository.

Under Repository name, give a name to your repository

▪ Give some Description about your repository under the Description section.

For a free repository, choose public.

 ▪ For a private repository, a monthly premium needs to be paid

▪ Finally, click on Create Repository.

To add Remote repository to local use git add remote followed by remote link:

Syntax: git add remote origin <remotelink>

To push Local repository to remote repository, use the push command Syntax: git push origin master

▪ The changes can be seen in the Remote repository

Files can be created and edited on remote

To list all the remotes attached to your Local repository Syntax: git remote –v




Fetch command copies the changes from remote to the local repository

Syntax: git fetch origin

▪ Fetch does not affect the present working directory

 

 

Pull copies all the changes from remote to the local repository

▪ It then merges the changes with the present working directory Syntax: git pull origin

Branches and Merge:

 

Assignment 1:

Problem Statement

Move the application code from local to Git & Git hub for better source code management.

Action Items:

                     Create a local git repository and move the entire code base to it

                     Create a new branch for a new feature you want to add to the application

                     Merge back the created branch with the master branch

                     Create a remote repository

                     Push the local repository to company’s GitHub remote repository

Assignment 2:

Problem statement:

Two developers to implement a new set of features in their software. Both started working separately, making their own copies of the same source code. Now, it has become difficult for them to track the changes they’ve made in the original code, and they are finding it difficult to merge their code together.

Action Items

§     Create two separate branches from master

§     Make changes in the same function of the source code in both the branches

§     Merge branch1 into the master

§     Try and merge branch2 into the master (merge conflict should arise)

§     Resolve the merge conflict.

 

 

No comments:

Post a Comment