Skip to content

Latest commit

 

History

History
79 lines (53 loc) · 5.19 KB

Branching and Merging in Git.md

File metadata and controls

79 lines (53 loc) · 5.19 KB

☆Branching and Merging in Git☆

  • vi filename.txt
  • Command used to write content in file.
    How do you use vi in text editor.

    1. To enter vi, type vi filename.txt
    2. To enter insert mode, type i
    3. Type in the text:------
    4. To leave insert mode and return to command mode, press: <Esc>
    5. To exit vi by typing :x You are back at the git bash.
    Note: vi(Visual Instrument) is the default editor. Using this we can edit an existing file.

  • cat filename.txt
  • To see the content of file.

  • git remote add origin _repository url_
  • This is command that says "push the commits in the local branch named master to the remote named origin". Once this is executed, all the stuff that you last synchronised with origin will be sent to the remote repository and other people will be able to see them there.

  • git remote -v
  • Shows URLs of remote repositories when listing your current remote connections.

  • git remote rm origin
  • All it means that your local copy of a repository is no longer associated with a particular remote. Alternatively, you can use the git remote rm command. git remote rm is simply a shorter version of the fit remote remove command. We can see our "origin" remote has been successfully removed.

  • git push origin master
  • In simple words git push command updates the remote repository with local commits. The origin represent a remote name where the user wants to push the changes. git push command push commits made on a local branch to a remote repository.

  • git restore --staged filename.txt
  • When you modify some file and added to git repository you can remove at any time if you didn't made any commit on that file that is called staging. Once you commit that file you can not unstage that file.

  • rm -rf filename.txt
  • To delete file.

  • git reset copy address
  • By default, git reset preserve the working directory. The commits are gone, but the contents are still on disk.

    How to remove the first commit in git?
    The first commit is what everything is built on. You could squash a few commits together, including the first commit, which becomes the new first commit, but what does it mean to even delete the first commit (or delete any but the last commit).

  • git stash
  • The git stash command takes your uncommitted changes (bth staged and unstaged), saves them away for later uses, and then reverts them from your working copy.

  • git stash pop
  • Git allows the user to re-apply the previous commits by using git stash pop command. The popping option removes the changes from stash and appies them to your working file.

  • git stash clear
  • Clear the stash area.

  • git clone __URL of forked repo in your repo__
  • It is primarily used to point to an existing repo and make a clone or copy of that repo at in new directory, at another location. The original repository can be loacted on the local file system or on remote machine accessible supported protocols. The git clone command copies an existing Git repository.

  • git remote add upstream __URL from where you have forked this repo__
  • You must configure a remote that points to the upstream repository in Git to sync changes made in the original repository with the fork.

  • git branch branch name
  • A branch represents an independent line of development. The git branch command lets you create, list, rename, and delete branches. It doesn't let you switch between branches or put a forked history back together again. For this reason, git branch is tightly integrated with the git checkout and git merge commands.

  • git checkout branch name
  • The git checkout command lets you navigate between the branches created by git branch . Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.

  • git push origin branch name
  • Pushing changes to the remote makes your commits accessible to others who you may be collaborating with. This will also update any open pull requests with the branch that you're working on.

  • git fetch --all --prune
  • git fetch --prune is the best utility for cleaning outdated branches. It will connect to a shared remote repository remote and fetch all remote branch refs. It will then delete remote refs that are no longer in use on the remote repository

  • git reset --hard upstream/main
  • git pull upstream main
  • The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. Merging remote upstream changes into your local repository is a common task in Git-based collaboration work flows.