0% found this document useful (0 votes)
21 views4 pages

Day 3

This document provides a comprehensive overview of essential Git commands for various tasks such as configuring user information, creating and managing repositories, handling branches, and using tags. It includes specific command syntax for actions like adding files, committing changes, pushing to remote repositories, and resolving merge conflicts. Additionally, it outlines the directory structure and branching strategies within Git.

Uploaded by

junaid
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)
21 views4 pages

Day 3

This document provides a comprehensive overview of essential Git commands for various tasks such as configuring user information, creating and managing repositories, handling branches, and using tags. It includes specific command syntax for actions like adding files, committing changes, pushing to remote repositories, and resolving merge conflicts. Additionally, it outlines the directory structure and branching strategies within Git.

Uploaded by

junaid
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/ 4

GIT

Git commands

Git task Notes Git commands

Configure the author name and email git config --global user.name "Sam Smith
Tell Git who you address to be used with your commits. git config --global user.email
are Note that Git strips some characters (for sam@example.com
example trailing periods) from user.name.

Create a new local


git init
repository

Create a working copy of a local


git clone /path/to/repository
Check out a repository:
repository
For a remote server, use: git clone username@host:/path/to/repo

git add <filename>


Add files Add one or more files to staging (index):
git add *

Commit changes to head (but not yet to


git commit -m "Commit message"
the remote repository):
Commit
Commit any files you've added with git
add, and also commit any files you've git commit -a
changed since then:

Send changes to the master branch of your


Push git push origin master
remote repository:

List the files you've changed and those you


Status git status
still need to add or commit:

Dev0ps Krishna 1
If you haven't connected your local
repository to a remote server, add the git remote add origin <server>
Connect to a server to be able to push to it:
remote repository
List all currently configured remote
git remote -v
repositories:

Create a new branch and switch to it: git checkout -b <branchname>

Switch from one branch to another: git checkout <branchname>

List all the branches in your repo, and also


git branch
tell you what branch you're currently in:

Delete the feature branch: git branch -d <branchname>


Branches
Push the branch to your remote
git push origin <branchname>
repository, so others can use it:

Push all branches to your remote


git push --all origin
repository:

Delete a branch on your remote


git push origin :<branchname>
repository:

Update from the Fetch and merge changes on the remote


git pull
remote repository server to your working directory:

To merge a different branch into your


git merge <branchname>
active branch:

View all the merge conflicts: git diff


View the conflicts against the base file: git diff --base <filename>
Preview changes, before merging: git diff <sourcebranch> <targetbranch>

After you have manually resolved any git add <filename>

Dev0ps Krishna 2
conflicts, you mark the changed file:

You can use tagging to mark a significant


git tag 1.0.0 <commitID>
changeset, such as a release:

CommitId is the leading characters of the


Tags
changeset ID, up to 10, but must be git log
unique. Get the ID using:

Push all tags to remote repository: git push --tags origin

If you mess up, you can replace the


changes in your working tree with the last
content in head: git checkout -- <filename>
Changes already added to the index, as
Undo local well as new files, will be kept.
changes
Instead, to drop all your local changes and
git fetch origin
commits, fetch the latest history from the
server and point your local master branch
git reset --hard origin/master
at it, do this:

Search Search the working directory for foo(): git grep "foo()"

GIT- Directory structure


 Master – Root directory and default one
 Branches – maintained for releases
 Tags – maintained for sub releases

GIT-Branching and commands


 Default branch is master
 >git branch --name of the branch
 >git branch Release1 --Release1 branch will created under master->Release1
 >git checkout Release1 --switch to Release1 branch

Dev0ps Krishna 3
 > git checkout –b Release1 --create and switch to branch
 >git branch –a --list all branches
 >git branch –v --list info branch
 >git branch –r --list remote branches
 >git branch –m Release1 Release2 --rename a branch
 >git push origin Release1 --push to release1 branch
 >git fetch origin Release1 Release1:Release1 –pull the branch changes by other user
 Git ls-tree –r release1 -list files in a branch
 >git branch –d Release1 -delete a branch in local repo
 Git checkout - -orphan release1 -creates empty branch
 >git push origin :ref/heads/Release2 --delete the same branch from remote repo
 >git diff Release1 Release2 --difference between branches

GIT Tags and commands


 Tags are read only
 >git tag tag_1.0 --create a tag
 >git show tag_1.0 --show git tag revision
 >git tag --list all tags
 >git tag tag_1.1 –m “Release1.0 is complete” --create an annotated tag with msg
 >git checkout tag_1.0 --checkout to tag
 >git push origin tag_1.1 --push to a specific tag
 >git tag –d tag_1.0 --delete a tag
 >git push origin :refs/tags/tag_1.0 --delete the same on remote repo

Dev0ps Krishna 4

You might also like