Git
Git is software for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows.
Installation in Ubuntu
Before the Git installation,update the system.
sudo apt update -y
After completing the updating process,install the Git
sudo apt-get install git
Commands and Operations
Check the version of git
git –version
Firstly, setting up Git
git config –global user.name “safwan”
git config –global user.email “safwanpaloli6@gmail.com”
Initialization Git
git init creates an empty Git repository or re-initializes an existing one. In essence, it creates a .git directory with subdirectories and template files. Running a git init in an existing repository will not overwrite things that are already there. Instead, it picks up the newly added templates.
git init
Create a file, file name is 1.txt
touch 1.txt
Add content to 1.txt using nano editor.
Check the Git status
git status
The files are untracked, so add them to git and commit
Files can differently add to git
A specific file is add to git
git add 1.txt
Add all files to git
git add -A
git add .
git add –all
After the file add and commit a message.
git commit -m “message type here”
Check the log
git log
Add more content on 1.txt file, and add file to git and again to commit file
git log –all
Here see that Commit IDs are unique SHA-1 hashes that are created whenever a new commit is recorded. If you want to push changes to such a repository, you can use the workspace command line to manually commit and push to a new branch.
Create a new branch
Created two branches, One is that feature and design.
git branch feature
git branch design
List the git branches
git branch
See that now branch is pointed to master. Master branch is default branch in git.
Now change to feature branch.
git checkout feature
Again Add some text to 1.txt
Check the different between before commit and after commit.
git diff
The last commit may need to be removed.
git stash
To Delete a local branch.
git branch -d design
Create a Repository in Github
Log in and visit the GitHub homepage to create a new repository on GitHub.
Push a branch to Github
git remote add new_repo https://github.com/safwanpaloli/new_repo.git
git push new_repo master
Uploading files with a Github password wasn’t possible; we needed to create an access token.
Create a Personal Access Token
Settings-> Developer Settings -> personal access token -> Generate new token
copy the token
Push branch to github
git push new_repo master.
Note : Use Personal access token is the password of git when the push the branch.
Check the git repository.
Successfully branch pushed to github.
Have a Nice Day…