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

General Q&A related to Git and GitHub

Q1: What is the difference between Forking and Cloning on GitHub? Answer:  # When you say you are Forking a repository you are basically creating a copy of the repository under your GitHub ID. The main point to note here is that any changes made to the original repository will be reflected back to your forked repositories(you need to fetch and rebase). However, if you make any changes to your forked repository you will have to explicitly create a pull request to the original repository. If your pull request is approved by the administrator of the original repository, then your changes will be committed/merged with the existing original code-base. Until then, your changes will be reflected only in the copy you forked. In short: The Fork & Pull Model lets anyone fork an existing repository and push changes to their personal fork without requiring access be granted to the source repository. The changes must then be pulled into the source repository by the project maintaine...

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...

How to Backtrack- Learn different ways to undo changes made to a Git project and when to use them.

Head commit : In Git, the commit you are currently on is known as the  HEAD commit. In many cases, the most recently made commit is the HEAD  commit. To see the  HEAD  commit, enter: git show HEAD The output of this command will display everything the  git log command  displays for the  HEAD  commit, plus all the file changes that were committed. For example:  Enter the command to show the  HEAD   commit. Notice the output. The ghost's most recently added line is in green text. Git Checkout: What if you decide to change the ghost's line in the working directory, but then decide you wanted to discard that change? You  could  rewrite the line how it was originally, but what if you forgot the exact wording? The command git checkout HEAD filename will restore the file in your working directory to look exactly as it did when you last made a c...