Skip to main content

Basic git commands to handle codes




Creating a Repository on GitHub:
------------------------------------------

1. Sign in to GitHub
2. Click the "+" sign beside your profile and click "New Repository"
3. Provide repository name and other necessary things if needed.


Pushing Code/project folder into GitHub Repository:
-------------------------------------------------

1. Go to the project location on your pc/laptop.
2. Enter into the Project.
3. Right click on mouse and select "Git Bash Here"
4. Run the following commands SEQUENTIALLY -

           git init
           git add -A (add your files)
           git status
           git commit -m "Your Message" (commit locally)
           git remote add origin GITHUB HTTPS PROJECT LINK
                                             HERE (add your origin)
           git remote add origin https://github.com/yourprofile/yourproject.git
         
           git push -u origin master (push it upstream)
       

5. Login popup window will appear to log into GitHub.

Congratulations! You have pushed your code in Github public repo !!!!!



For each new change from Onward:
----------------------------------------------

1.  git status
2. git add -A
3. git commit -m "Commit Message is here"
4. git push -u origin master

================== day to day used commands ================

git checkout master
git pull origin master
git merge <the branch that you want to merge with checkout branch>
git push origin master

----------------------------

1. On your branch:

git fetch && git rebase origin/master
// it does the same action as the 'rebase' button on web view; or CLI version of rebase with master.

git push origin branch_name -f


2. merge your branch with 'fast-forward only' options

checkout master

git fetch && git pull
// up-to-date local master with origin master

git merge origin/<YOUR BRANCH> --ff-only

git push origin master -f
// if we do push on master directly

Comments

Popular posts from this blog

Git Branching- Learn how to manage multiple versions of a project with Branching.

Git Branch: Up to this point, you've worked in a single Git branch called  master . Git allows us to create  branches  to experiment with versions of a project. Imagine you want to create version of a story with a happy ending. You can create a new branch and make the happy ending changes to that branch only. It will have no effect on the  master branch until you're ready to merge the happy ending to the master branch. In this lesson, we'll be using Git branching to develop multiple versions of a resumé. You can use the command below to answer the question: “which branch am I on?” Command : git branch Check what branch you are currently on.  In the output, the * (asterisk) is showing you what branch you’re on. The diagram above illustrates branching. 1. The circles are commits, and together form the Git project's commit history. 2. New Branch  is a different  version  of the Git project. It contains commits...

Basic Git Workflow- how it's work

Basic Git Workflow: Git is a software that allows you to keep track of changes made to a project over time. Git works by recording the changes you make to a project, storing those changes, then allowing you to reference them as needed. Turning a directory into a project>>  command: git init The word  init  means  initialize . The command sets up all the tools Git needs to begin tracking changes made to the project. Output: would be like-  Initalized an empty g it repository in /home/ccuser/workspace/sorcerers-code/.git/ By the above output, we could say that  The Git project was created. Git workflow: A Git project can be thought of as having three parts: 1. A  Working Directory : where you'll be doing all the work: creating, editing, deleting and organizing files 2. A  Staging Area : where you'll list changes you make to the working directory 3. A  Repository : where Git permanently stores those chan...