Before you go, check out these stories!

0
Hackernoon logoStep-By-Step Guide To Push Your First Project On GitHub!! by@skyline

Step-By-Step Guide To Push Your First Project On GitHub!!

Author profile picture

@skylineAkash

Developer || Writer || Engineer

Steps that can make your workย half!!
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.
  1. Automatic Method (Usingย Xclip)
On Ubuntu
sudo apt-get install xclip
on Manjaro
Open Octopi -> Download Xclip
Xclip-set clip <~/.ssh/id_rsa.pub

2. Manualย Method

Home/.ssh/id_rsa.pub
Open 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ย :

  1. 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 origin
git 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

.gitignore file

Useful Hints

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

For GitIgnore

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___ย :)

Tags

Join Hacker Noon

Create your free account to unlock your custom reading experience.