Git is Open Source Repository for source control. This will be commonly used in IT industry for code checkin and checkout. We will use gitbash to setup git in local repository. Git can be used as server and local respository. Sometime git will be used as local respository. In server bitbucket will be used as central repository.
In this post we can go through all git commands useful for day to day activities.
#to clone the repository from bitbucket
git clone "clone link"
To Establish the connection between respository and local systems we need either ssh keys or http access tokens.
First we can setup ssh keys then setup http token
#to setup keys firsr we need generate keys
ssh-keygen -t rsa -b 4096 -C "mail id"
Get the public key and configure in bitbucket under my account --> ssh keys and upload the ssh public key
Then Open the but bucket respository and select ssh and copy the link to clone from local system
#to clone the repository from bitbucket using ssh connection
git clone ssh://git@bitbucketserver.com/repo/reponame.git
Once Cloned you can check status using the git status command
#to check the status of local system
git status
#the above command will show the the current state of local repository
Once Cloned you can create your feature branch using git branch command
#to create feature branch after cloning
git checkout feature/mybranch
#the above command will a branch in local repository
you can place your modified files in the local path and again check status
#check status of local system
git status
#now it will show untracked files: the files you modified
use git add command to add the files
#to add files to to git local branch
git add filename
#This will add files to git local repository. We can also use . symbol to add all untracked files
git add .
To save this untracked files in local we use git commit
#to save files to repository
git commit -m "adding the modified file"
# -m will be used for comment to understand why we are adding or modifying the files
To push the files to server we can use git push
#to push files to repository
git push
Similarly we can use https connection pull or push the files to repository
#to check the current config
git config -l
Once config verified, we can setup credentails in local to connect git. Please note that we need to have atleast developer access to the respective respository to perform all the activities
#to check the credetials and config required in local system
git config --global credential.helper manager
git config --global user.email "email id"
git config --global user.name "user name"
git config --global core.autoclrf false
git config --global http.sslverify false
In Local system go to control panel --> Windows Credentials -->Add generic credentials.
Add bit bucket https site url git:bitbucketurl
Once above setings completed in local, then login to bit bucket --> manage accounts --> HTTP access tokens -->create token
Save this token for future purpose
#Open git bash in local and clone the repository
git clone https://login@bitbucketurl/scm/repo/reponame.git
To Create new branch
#Below command will create new branch gittest.
git branch gittest
To check the created branch
#Below command will list all braches
git branch -a
To push the changes from local to remote branch. we need to following in sequence
#Below command push the local changes
git add filename
git commit -m "reason for adding"
git push -u origin localbranchname
To change identity used for the commit.
#Below command will change identity for the commit
git branch -amend --reset-author
To push the change to upstream if there is no upstream
#Below command will push changes to upstream
git push --set-upstream origin feature/branchname