Sunday, 6 December 2020

Basic Git commands

Basic Git commands 


GIT REPOSITORY- PULL -PUSH CODE STEPS:

1.Tell GIT who you are by giving your name and email id [git config --global user.name "Sam Smith"] [git config --global user.email sam@example.com ]

2.Create a local folder in system and place files

3.Initialize local folder as Git repo- - [git init ]

4.Staging/Stash - first commit -code commits from local to stash [ git add*]

5.git status - to see list of files with commit level 1 

6.Commit - final commit -which commits code in GitHub [git commit -m "fitst commit"]

7.push changes to master branch -  [git push origin master]


Eclipse -Import Projects-update changes in project 

move changes to staging from the local working repo [git add*]

verify changes are moved to staging?  [git status]

then commit changes to GITHUB- [git commit -m "changes are done"]

push changes to master branch -  git push origin master 


8.PULL latest version/changes by others to local [ git pull origin master]

git clones entire repository to local folder 


BRANCHING: 

If user 1 is changing code -then user 2 will be impacted with those changes, so we wil take sub branch (copy of master)

and continue with changes by user 1, so it won't impact user 2.

Merge copy branch with master branch and use by user 1 and user 2


9.git checkout -b developbranch[creating new branch copy of mastar]

10.git branch [will show the list of branches]

11.git push origin developbranch [to push new branch to githug]


12.git pull origin developbranch [dev 2 pulled new branch code]

13. git checkout developbranch [switch from mastar to devbranch]

 

MERGE BRANCHES:

14.switch to master bracnh [ git checkout master]

15.merge developbranch with active master [git merge developbranch]


MERGE CONFLICTS:

when merge conflict happens- check those specific files and do manual changes -then merge to master 


***Eclipse - project - right click- Team- Switch To- Pull/Push options to GIT

==================================================Start a working area:

Clone -clone a repository

init- create a emty GIT repo/reinitialise an existing one

Work on current change:

Add- add file content to the Index

mv - move or rename a file/directory/symlink

restore -restore working tree files

rm- remove files from the working tree and from index

sparse checkout - Initialize and modify the sparse-checkout

Examine the history and state:

bisect - use ninary search to find the commit that itroduced a bug

diff- show changes between commits

grep - print lines matching pattern

log - show commit logs

show -show various types of objects

status - show the working tree status 

grow, mark and tewak your commit history 

branch- List, create , delete branches

commit- record changes to the repository

merge - join two or more development history together

rebase- reapply commits on top of the another base tip 

reset- reset current head to the specified state 

switch - switch branches

tag- create, list , delete or verify a tag object signed with GPG

Collaberate: 

fetch- Download objects and refs from another repository

pull- Feth from and integrate with another repository 

push- Update remote refs along with associated objects 


Here is a list of some basic Git commands to get you going with Git.

For more detail, check out the  Atlassian Git Tutorials  for a visual introduction to Git commands and workflows, including examples.

 Source: https://confluence.atlassian.com/bitbucketserver/basic-git-commands-776639767.html

Git taskNotesGit commands
Tell Git who you areConfigure the author name and email address to be used with your commits.

Note that Git strips some characters (for example trailing periods) from user.name.

git config --global user.name "Sam Smith"

git config --global user.email sam@example.com

Create a new local repository 
git init
Check out a repositoryCreate a working copy of a local repository:
git clone /path/to/repository
For a remote server, use:
git clone username@host:/path/to/repository
Add filesAdd one or more files to staging (index):
git add <filename>

git add *
CommitCommit changes to head (but not yet to the remote repository):
git commit -m "Commit message"
Commit any files you've added with git add, and also commit any files you've changed since then:
git commit -a
PushSend changes to the master branch of your remote repository:
git push origin master
StatusList the files you've changed and those you still need to add or commit:
git status
Connect to a remote repositoryIf you haven't connected your local repository to a remote server, add the server to be able to push to it:git remote add origin <server>
List all currently configured remote repositories:git remote -v
BranchesCreate 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 tell you what branch you're currently in:
git branch
Delete the feature branch:
git branch -d <branchname>
Push the branch to your remote repository, so others can use it:
git push origin <branchname>
Push all branches to your remote repository:
git push --all origin
Delete a branch on your remote repository:
git push origin :<branchname>
Update from the remote repositoryFetch and merge changes on the remote server to your working directory:git pull
To merge a different branch into your active branch:
git merge <branchname>
View all the merge conflicts:

View the conflicts against the base file:

Preview changes, before merging:

git diff

git diff --base <filename>

git diff <sourcebranch> <targetbranch>
After you have manually resolved any conflicts, you mark the changed file:
git add <filename>
TagsYou can use tagging to mark a significant changeset, such as a release:
git tag 1.0.0 <commitID>
CommitId is the leading characters of the changeset ID, up to 10, but must be unique. Get the ID using:
git log
Push all tags to remote repository:
git push --tags origin
Undo local changesIf you mess up, you can replace the changes in your working tree with the last content in head:

Changes already added to the index, as well as new files, will be kept.

git checkout -- <filename>
Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this:
git fetch origin

git reset --hard origin/master
SearchSearch the working directory for foo():git g