Git is a free and open source distributed version control system.

Generating a new SSH key and adding it to the ssh-agent using git bash

Step1 :
ssh-keygen -t rsa -b 4096 -C (gmail id)

Then u will press enter and at default location shown there: (/c/Users/XXX/.ssh/id_rsa)

start the ssh-agent in the background
$ eval $(ssh-agent -s)

Now add it to agent

ssh-add ~/.ssh/id_rsa

$ git init
With this command we will initialise local directory as git repository. Till now our code is in working area

$ git add . – with dot

Adds the files in the local repository and stages them for commit. These files are prepared to be commited. So now files are moved from working area to staging area

$ git status
to see ur files. In staged, unstaged or untracked status. After commiting u will not see the file here.

$ git commit -m “First commit”

Commits your tracked changes on your local repository and prepares them to be pushed to a remote repository. So now files moves from stage to local repo.

git remote add origin git@github.com:Code-decode-learning/git-demo.git
add url for remote repository in which your local repo will be pushed .

git remote -v
Verify new remote url.

$ git push –u origin master
Pushes the changes in your local repository up to the remote repository you specified as the origin

for forked repos :

Go to your .config file in .git and check upstream and origin.

Upstream should be from where u can take pull. Means your main repo of organisation.

Origin must be your forked where you will push your code and raise a pull request so that on approval those changes can be merged to upstream branch or organisation.

git remote add upstream (url).

git remote add origin(url).

We have already seen:
Git init [repo name] : This command is used to start a new repository.
Git clone : used to obtain a repository from an existing URL into local repository.
Now:

Git add [file] - This command adds a file to the staging area.
Git add .(dot) - This command adds one or more to the staging area.

git diff: Show unstaged changes between your index and working directory.

git commit -m “[ Type in the commit message]”
Usage : git commit –am “my message”

git status : List which files are staged, unstaged, and untracked.

Git log : Display the entire commit history using the default format. For customization see additional options.

git push origin $branchname:$remote_branchname

Git pull -) this command will pull changes from default remote repository which is origin n not upstream, if wanna pull from upstream then use command git pull upstream master.

git fetch: fetches the changes from remote repository but will not affect your local so will not give u any merge confict,
The interesting thing about the fetch command is that it doesn’t actually affect anything in your local repo. No working changes will be lost, and you’ll see no direct affect on your local branches. This is because Git keeps fetched content separate from your own repo’s content until it is merged in.

git fetch (remote-repo)
$ git merge FETCH_HEAD

So obviously the big difference between fetch and pull is that pull actually performs a fetch in addition to a merge.

#git #github #developer

Git and GitHub Crash Course || Git Tutorial for Beginners
5.50 GEEK