← Back to Git Course | Chapter 4: Remote Repositories | Lesson 7 of 11

Git push Command

git push online class folder में अपना homework सौंपने जैसा है ताकि बाकी सब वह देख और इस्तेमाल कर सकें जो आपने किया।
Syntax
bash
git push remote_name branch_name
git push -u remote_name branch_name
git push --all remote_name

Git Push क्या है?

git push आपकी current local branch पर commits को एक remote repository पर matching branch में upload करता है, आपके काम को उस remote तक access रखने वाले हर किसी के लिए visible और available बनाते हुए।

उदाहरण: What is Git Push?

bash
git push origin main

Remote में एक Branch Push करना

पहली बार जब आप एक बिल्कुल नई local branch push करते हैं, git push -u origin <branch> (या --set-upstream) इसे same नाम की एक remote branch से link करता है, इसलिए उस branch से हर future push या pull बिना extra arguments के एक plain git push हो सकता है। upstream link एक बार set हो जाने के बाद, उसी branch की बाद की pushes को सिर्फ git push चाहिए (या explicitly git push origin <branch>), क्योंकि Git को पहले से पता है कि कौन सी remote branch update करनी है -- scripts या CI में branch को explicitly नाम देना अभी भी उपयोगी है जहाँ current branch assume नहीं होनी चाहिए।

उदाहरण: Pushing a Branch to Remote

bash
git push -u origin feature-login

सभी Branches Push करना

git push --all एक command में हर local branch remote पर भेजता है, जो convenient है जब आप locally कई branches में काम कर रहे हों और उन सबको एक साथ publish करना चाहें।

उदाहरण: Pushing All Branches

bash
git push --all

Tags Push करना

Tags default रूप से एक normal push में शामिल नहीं होते -- उन्हें explicitly upload करने के लिए आपको git push --tags (या सिर्फ एक के लिए git push origin <tagname>) चाहिए, क्योंकि tags को regular commit history से अलग treat किया जाता है।

उदाहरण: Pushing Tags

bash
git push --tags
git push origin v1.0

Force Pushing को Safely करना

Force pushing (git push -f) remote की history को आपके local version से overwrite कर देता है, जो चुपचाप एक teammate की पहले से pushed commits destroy कर सकता है। git push --force-with-lease safer alternative है: यह remote को overwrite करने से मना कर देता है अगर उसमें ऐसी commits हों जो आपने नहीं देखीं।

उदाहरण: Force Pushing Safely

bash
git push --force-with-lease
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक नई branch को plain git push से push करना और no upstream branch पाना, जबकि पहली push को -u origin <branch> चाहिए।
  2. rejected (non-fast-forward) पाना और इसे --force से force करना, पहले git pull चलाने के बजाय teammates की commits overwrite करते हुए।
  3. यह भूल जाना कि git push tags नहीं भेजता, जबकि आपको git push --tags चाहिए।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.