Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Steps that can make your work half!!
Photo by Samuel Zeller on Unsplash
First select your project & open your terminal in your project’s root directory.
1. Check for Git Version
git --version
If it is not showing the version of git then go to the official website of git and download the git according to OS of your system.
2. If we are setting up the git for the first time, we can configure the git with name & email.
git config --global user.name "Your_Name"git config --global user.email "Your-Email"
3. Initialize Git Repository
git init
Note:- On your Project’s root directory
It initializes the git repository in local project & will make .git folder that contain important folders and files.
4. Commiting files into the git repo.
There are three steps :-
Step 1 : We need to add a file to staging area .
git add <File_Name> {{For Single File}}git add . {{For all the files in current Directory}}
Note :- In place of <File_Name> add your file and if you want select all the files in current directory then use {{ . }} or {{ * }}
Staging area :- Staging area is that area where we can buy some items and put them in bucket .
To check,if files are added or not,use this:
git status
Step 2 : Commit a file into the git repo is to write a commit message.
m = message
git commit -m "First Commit"
Note :- In the “Double Quotes”, you should write your message.
Step 3 : Push the file into a remote repository. {{Github}}
Now create your account on git-hub and create a repository .
To add files in your remote repo use this :
git remote add origin git@github.com:"Username_on_github"/"Repository_Name"
Note :- This above command is a single command & Now place your git-hub username (without any quotes) and put your repository name (without any quotes).
Like this
git remote add origin git@github.com:XYZ/project.git
And if you don’t understand this then go to your repository on git-hub and click on clone or download button and copy url with SSH method.
To check
git remote -v
5. Create SSH Key.
Why we use SSH?
By using the ssh protocol, we can connect and authenticate to remote servers and services. With ssh keys we can connect to GitHub without supplying our username and password at each visit with the help of passphrase. In HTTPS method, you will need to fill our username and password at every visit, which will be very inconvenient.
Git associates a remote URL with a name and our default remote is usually called “Origin”
1. Generating New ssh key and adding it to a ssh agent.
ssh-keygen -t rsa -b 4096 -C "email"
Note :- Place your email in “double quotes”.
This creates a new ssh key using the provided email as a label.
1.1. For default file Press {{ ENTER }}
/home/{{username_of_pc}}/.ssh/id_rsa: ENTER
1.2. Enter a passphrase.
1.3. Now our identification has been saved in
Private Key : /home/{{username_of_pc}}/.ssh/id_rsa& Public Key : .ssh/id_rsa.pub
2. Adding our ssh key to the ssh agent
eval "$(ssh-agent -s)"it gives like {{agent_id : 15800}}
3. Now we add SSH Private key to ssh-agent to our default path.
ssh-add ~/.ssh/id_rsa
4. Adding a new ssh key to your github account.
Copy the ssh key to our clipboard.
- Automatic Method (Using Xclip)
On Ubuntusudo apt-get install xclip
on ManjaroOpen Octopi -> Download Xclip
Xclip-set clip <~/.ssh/id_rsa.pub
2. Manual Method
Home/.ssh/id_rsa.pubOpen this file and copy your key.
Now goto github.com ➢➢ Under Profile Photo (Drop Down) ➢➢ Settings ➢➢ Use SideBar {{ SSH & GPG Keys }} ➢➢ Then go to this directory on your computer {{Home/.ssh/id_rsa.pub}}Open this file and copy your key.
Create new SSH key ➢➢ Title the filed with descriptive label ➢➢ Paste key into a “Key Field” ➢➢ Click on {{ Add SSH Key }}
5. Now for Testing SSH Connection.
ssh -T git@github.com
After running this , it will show this messege on terminal!!
Hi {{ USERNAME }}! You've successfully authenticated but github does not provide shell access.
6. Final PUSH
git pull --rebase origin master git push origin master
Note : Change ‘master’ whatever branch to push.
Then you can successfully push your file to remote server and you can setup a SSH Connection.
To check the connection
git log
Some other useful git concepts.
There are concepts that can help you to understand the git more deeply.
1. Create a new branch.
git checkout -b Branch_name
If you want to switch back to master branch.
git checkout master
If you want to delete the branch.
git branch -d Branch_name
2. Update and Merge.
To update local repository to the newest commit
git pull
To merge another branch in active branch.
git merge <branch>
In both cases git tries to auto-merge changes. unfortunately this is not always possible and results are in conflicts.
we can merge those conflicts manually by editing the files shown by git.
git add <filename>
Before merging changes we can preview.
git diff <source-branch> <target-branch>
3. Tagging.
we can give tag (line 1.0.0)
git tag 1.0.0 {{1b2eld63ff}}
Note : {{ this is the first 10 characters of commit id. }}
4. Git Log.
By Git Log we can study repository history.
Advanced :
- See only the commits of a certain author.
git log --author <name>
2. Very compressed log.
git log --pretty=oneline
More preferable format
git log --pretty=format:"%h - %an, %ar : %s"
3. It will only show the files that have changed.
git log --stat
5. Replace Local Changes.
git checkout --filename
(if we did something wrong) then this will replace file with the last content in HEAD.
If we want to drop all local changes and commits, fetch the latest history from server
git fetch origingit reset --hard origin/master
6. Never forget to create your .gitignore file.
Gitignore file ➢➢ Is a file that specifying the files or folders that we want to ignore.
There are several ways to specifying those
- Firstly, you can specifying by the specific filename. Here is an example, let’s say we want to ignore a file called readme.txt, then we just need to write readme.txt in the .gitignore file.
- Secondly, we can also write the name of the extension. For example, we are going to ignore all .txt files, then write *.txt.
- There is also a method to ignore a whole folder. Let’s say we want to ignore folder named test. Then we can just write test/ in the file.
Like this
1. Built in git Gui.
gitk
2. Use colorful-git output.
git config color.ui true
3. Use interactive adding.
git add -i
Some useful Article’s and Repositories
- github/hub {{ A command-line tool that makes git easier to use with GitHub}}
- 15 Git Commands You May Not Know
- Adding an existing project to GitHub using the command line
- How to become a Git expert
For GitIgnore
- Git- gitIgnore Documentation.
- .gitignore file — ignoring files in Git | Atlassian Git Tutorial
- gitignore.io
Photo by Pankaj Patel on Unsplash
Lastly, You are requested to share your views on this article. :)
Find something useful? Hold down the 👏 to support and help others find this article. Thanks for reading!!
Follow me on Instagram @hypnosisss___ :)
Step-By-Step Guide To Push Your First Project On GitHub!! was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.