0% found this document useful (0 votes)
8 views

GittaskAbrar

The document outlines a series of Git tasks to be performed on a Linux server, including creating directories and files, installing Git, initializing repositories, managing branches, and interacting with remote repositories. It covers tasks such as committing changes, merging branches, fetching updates, and handling commits and branches. Additionally, it provides commands for undoing changes, viewing commit history, and managing remote repository access.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

GittaskAbrar

The document outlines a series of Git tasks to be performed on a Linux server, including creating directories and files, installing Git, initializing repositories, managing branches, and interacting with remote repositories. It covers tasks such as committing changes, merging branches, fetching updates, and handling commits and branches. Additionally, it provides commands for undoing changes, viewing commit history, and managing remote repository access.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

GIT TASKS

Task1:

1. Log in to the Linux server, create a directory, and create a filename index.txt (enter hello worked
text inside file)inside the directory.

Mkdir abrargittask

cd abrargittask

echo "git task" > gtask.txt

2. Install Git on the Linux server, then check the Git version.

sudo apt-get install git

git --version

3. Initialize a Git repository in the created directory, add the changes to the staging area, and
commit the changes.

git init

git add gtask.txt

git commit -m "first commit"

4. Create remote repo and push changes to that remote repo.

git remote add origin [email protected]:shaik817/gtask.git

git push -u origin main

5. Add git configuration user name and email

git config user.name "shaik abrar ahmed"

git config user.email "[email protected]"

6. Finally, check the commit list.

git log --oneline


Task 2:

1. Create a branch and switch to it, then edit the `index.txt` file to add "hello git".

git branch newgit

git checkout newgit

echo "hello git" >> index.txt

git add index.txt

git commit -m "Added hello git"

2. Create a branch and automatically switch to the newly created branch.

git checkout -b newgit2

3. Check the list of Git branches.

git branch

4. Switch from one branch to another without using the `git switch` command.

git checkout main

Task3:

1. Create two branches, one named `feature` and the other named `test`, each containing the file
`index.txt` with different content. Merge these two branches, but keep only the changes from
the `test` branch.

git branch feature

git branch test

git checkout main

git merge -X theirs test

2. Combine the changes from the two branches without using the `git merge` command.

git cherry-pick <[email protected]:shaik817/feature.git>

git cherry-pick <[email protected]:shaik817/test.git>

3. Display the commit history in a single line


git log --oneline

Task4:

1. Connect a remote repository to your local repository on a Linux server, then create a file in the
remote repository.

git remote add origin <[email protected]:shaik817/gtask.git>

2. Fetch the changes from the remote repository to your local repository without committing the
changes to the current branch.

git fetch origin

3. Fetch the changes from the remote repository to your local repository and commit the changes
to the current branch.

git pull origin main

4. Display the list of branches in the remote repository using a Linux command.

git branch -r

5. View the latest 5 commits in the repository in linux server.

git log -5

Task:5

1. Describe and Implementing the branching strategy you have followed.

2. Rename a branch.

git branch -m test test2

3. Delete a branch both locally and remotely.

git branch -d test2

git push origin --delete test2

4. Show the differences between two commits.

git diff commitid1 commitid2


Task:6

1. Create three branches (`dev`, `test`, `prod`) each containing the file `index.txt`.

git checkout -b dev

git checkout -b test

git checkout -b prod

2. Switch to the `test` branch, create a file `test.txt`, add and commit the changes.

git checkout test

echo "abc" > test.txt

git add test.txt

git commit -m "new commit"

3. Copy the specific changes from the `test` branch (`test.txt`) into the `dev` and `prod` branches
without merging branches.

git checkout dev

git cherry-pick commitid

git checkout prod

git cherry-pick commitid

4. Finally, check the commit history in each branch to ensure the changes were successful.

git log --oneline

Task:7

1. Create two branches (dev and test) with the file index.txt.

git checkout -b dev

git checkout -b test

echo "abc" > index.txt

git add index.txt


2. In the dev branch, create another file dev.txt and add changes to the staging area. Immediately
switch to the test branch and create a file test.txt without showing the dev branch changes in
the test branch.

echo "Dev" > dev.txt

git add dev.txt

git checkout test

echo "Test" > test.txt

3. In the test branch, add and commit the changes, then switch back to the dev branch to add and
commit the already staged changes.

git add test.txt

git commit -m "newcommit"

git checkout dev

git add

git commit -m “commitnew”

Task:8

1. I want to download files from an existing remote repository to my local machine.

git clone [email protected]:shaik817/gtask.git

git pull

2. I want to give access to another user; how can I do that?

By sharing the git url of public repo

3. Fork a repository in the remote repository.

It can be done using the fork application in github

4. Generate an HTTP token on GitHub.

It can be done using git settings , go to developer settings by adding personal access token generation
Task:9

1. I want to undo the changes currently in the commit history and working directory.

git reset --hard HEAD

2. I want to undo the changes from the previous commit without altering the commit history.

git reset --soft HEAD~1

3. Create a directory, initialize a Git repository, then create a file named `index.txt` and commit the
changes.

Mkdir abrar

cd abrar

git init

echo "abc" > index.txt

git add index.txt

git commit -m "firstcommit"

4. Create another file named `feature.txt`, add it, and commit the changes.

Echo “abc” >feature.txt

git add feature.txt

git commit -m “secondcommit”

5. Delete the previous commit from the Git log.

git reset --hard HEAD~1

6. How can I revert to that deleted commit?

git reflog

Task:10

1. How to view the origin remote repository in the local setup.

git remote -v

2. How to remove the origin remote in the local setup.


git remote remove origin

3. How to view the remote repository with branches in the local setup.

git branch -r

4. How to delete a Git branch.

git branch -d branch_name

You might also like